Sql server 如何使用webservice将图像从swift保存到SQL Server数据库?
我使用UIImagePNGRrepresentation(图像)成功地将ipad签名转换为png图像。现在,我想使用web服务将此图像从swift存储到SQL Server数据库。我不知道该怎么做 这是我的swift密码Sql server 如何使用webservice将图像从swift保存到SQL Server数据库?,sql-server,swift,web-services,Sql Server,Swift,Web Services,我使用UIImagePNGRrepresentation(图像)成功地将ipad签名转换为png图像。现在,我想使用web服务将此图像从swift存储到SQL Server数据库。我不知道该怎么做 这是我的swift密码 UIGraphicsBeginImageContextWithOptions(self.signatureMainImageview.bounds.size, false, 0.0) self.signatureMainImageview.image?.drawInRect(C
UIGraphicsBeginImageContextWithOptions(self.signatureMainImageview.bounds.size, false, 0.0)
self.signatureMainImageview.image?.drawInRect(CGRectMake(0, 0, self.signatureMainImageview.frame.size.width, self.signatureMainImageview.frame.size.height))
let SaveImage: UIImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
let image = UIImagePNGRepresentation(SaveImage)
var CardDataObj = structCardData()
CardDataObj.CustomerSignature = image!
let requestCardData = NSMutableURLRequest(URL: NSURL(string: "http://URL")!)
requestCardData.HTTPMethod = "POST"
let postString = CardDataObj.jsonRepresentation
requestCardData.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding)
let task = NSURLSession.sharedSession().dataTaskWithRequest(requestCardData) {
data, response, error in
if error != nil {
print("error=\(error)")
return
}
print("response = \(response)")
let responseString = NSString(data: data!, encoding: NSUTF8StringEncoding)
print("responseString = \(responseString)")
}
现在我想知道如何在webservice中获取此图像?在webservice for image中使用哪种数据类型?sql for image中使用哪种数据类型?如何将此映像发送到sql
uploadTaskWithRequest:fromData:completionHandler
或其文件或流变体task.resume()
if let response = response as? NSHTTPURLResponse {
response.statusCode
response.allHeaderFields
}
我写了一篇关于使用流上传的文章,这可能会有一些用处。这里还有关于NSURLSession的内容
链接到的第一篇博客文章将为您提供一些PHP服务器端代码以接收流,但如果您不确定如何处理SQL,我建议将此问题分成两部分,分别提问。这与我的答案无关。我想使用WebService将签名图像存储在我的sql数据库中,为此,您需要知道如何从应用程序上载图像。如上所述,这是一个由两部分组成的问题,应该分为两部分:CustomerSignature是一个变量,datatype是NSDataRepresentation在
jsonRepresentation
中发生了什么?我假设对图像进行base64转换,以便将其包含在json中。关于将数据实际插入mysql数据库的讨论,您需要查看教程,最好是针对您使用的服务器端语言