Alamofire Encodes Image in Which Format

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



Leave a reply



Submit