Ive been recently trying to get AFNetworking to work as i did with native request, i have been always using AFNetworking for uploading POST or GET.but it never uploaded my image correct. it always uploaded to the server damaged and I've explained about the issue in this reference : Uploading image to server reached damaged using AFNetworking
I've tried to use native NSURLConnection.sendSynchronousRequest
with HTTP Body and it has been uploaded and not damaged. and this code fully work but i need it in AFNetworking because it only supports IOS 8 + and for more reasons.
let baseURL = ""
let selectedImage = self.userImage.image
let imageData = NSData(data: UIImageJPEGRepresentation(selectedImage!, 0.5)!)
let request = NSMutableURLRequest()
request.URL = NSURL(string: baseURL)
request.HTTPMethod = "POST"
request.addValue("image/jpeg", forHTTPHeaderField: "Content-Type")
let body = NSMutableData(data: imageData)
request.HTTPBody = body
do {
let responseData = try NSURLConnection.sendSynchronousRequest(request, returningResponse:nil)
let responseString = String(data: responseData, encoding: NSUTF8StringEncoding)
print("User image successfully uploaded navigating to home services")
} catch (let error as NSError) {
}