I have looked at questions like this or that one but it is still not working.
Also I have a question about what should I enter into fileURL
param from function multipartFormData.appendBodyPart
?
Should it be a way to image from PC, or image must be added to Images.xcassets? What should I send here?
It looks like you have three issues that you need to fix.
.POST
instead of POST
.fileURL
needs to be a valid NSURL
that points to a file on the file system. You cannot just use the filename.responseString
serializer, but named the third parameter in the closure JSON
. Then you are letting result
into s
and trying to print it out. The result
parameter doesn't even exist anywhere. Instead, you should print(JSON)
.Hopefully that helps clear things up a bit.
Try to use .POST
not POST
As an alternative solution upload an encoded file and send it as a parameter of POST.
// `data` is NSData
let base64String = data!.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.allZeros)
let parameters = ["image_data": base64String] as [String: AnyObject]
Alamofire.request(.POST, "http://your-url.com", parameters: parameters)
The cons of this method is that the data will get %33 larger due to encoding. If you have bandwidth problems it may not be a good solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With