How can I upload an image into my web service then I can save it on my server!
I have tried the below code using POST method but I got this error
(A potentially dangerous Request.Form value was detected from the client (uploadFile="<ffd8ffe0 00104a46 4...").)
func myImageUploadRequest() {
let imageData = UIImageJPEGRepresentation(myImageView, 1)
let boundary = generateBoundaryString()
var base64String = imageData.base64EncodedStringWithOptions(.allZeros)
let myUrl = NSURL(string: "http://xxxxx/UploadImageTest");
let request = NSMutableURLRequest(URL:myUrl!);
request.HTTPMethod = "POST";
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
if(imageData==nil) { return; }
var body = NSMutableData();
body.appendString("uploadFile=\(imageData)")
request.HTTPBody = body
let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
data, response, error in
if error != nil {
println("error=\(error)")
return
}
// You can print out response object
println("******* response = \(response)")
// Print out reponse body
let responseString = NSString(data: data, encoding: NSUTF8StringEncoding)
println("****** response data = \(responseString!)")
dispatch_async(dispatch_get_main_queue(),{
});
}
task.resume()
}
And this the POST SOAP on my Asp.net web service
POST /xxxx.asmx/UploadImageTest HTTP/1.1
Host: xxxx.com
Content-Type: application/x-www-form-urlencoded Content-Length: length
uploadFile=string&uploadFile=string