Trouble with Swift 4 Alamofire and encoding UIImage
If you are using multipartFormData type in server side please follow as like below code to upload your image:
let imgData = newImage.jpegData(compressionQuality: 0.2)!
let imageName = "testImage.jpg"
Alamofire.upload(multipartFormData: { multipartFormData in
multipartFormData.append(imgData, withName: "file",fileName: imageName, mimeType: "image/jpeg")
}, to:urlString) { (result) in
switch result {
case .success(let upload, _, _):
upload.uploadProgress(closure: { (progress) in
print("Upload Progress: \(progress.fractionCompleted)")
})
upload.responseJSON { response in
print("response.result :\(String(describing: response.result.value))")
}
case .failure(let encodingError):
print(encodingError)
}
}
Uploading Image to Server in Base64 using Alamofire iOS
Can you try removing the manually set headers headers: headers()
? Alamofire should be setting those headers for multipart form data and my guess it that you're overriding them with application/json
Related Topics
Add Value to Variable Inside Closure in Swift
Moving from Nsurlconnection to Nsurlsession for Soap Post in Swift
Issues with Uploading from Xcode 9 to App Store/ Itunes Connect
How to Get and Save The Mixed of Multiple Audios in to Single Audio in Swift
Navigationview Inside a Tabview Swift UI
Unexpectedly Found Nil While Unwrapping an Optional Value with Avaudioplayer
How to Show Cluster for Mkpolyline with Geojson Data View in iOS Swift
Syntax to Create Dictionary in Swift
Working Out The Start and End of a Day. Swift
How to Keep Nsmenuitem Selected in a Nspopover with Nsmenu
Swift: Right/Left Click on Nsstatusbar
Protocol with Associatedtype Protocol for Generic Functions
Transparency Issues with Repeated Stamping of Textures on an Mtkview