I am unable to upload images to server getting. Showing upload progress upload.uploadProgress but after upload.responseJSON is nil error.
I have tried my best but couldn't solve the issue. Please anyone can help me out. What am I doing wrong? when I debug it { (result) in switch result { result is invalid.
Postman key: (parameters)
ImageList -- for images
ProjectUnitID -- 8568816
Swift Code:
if asset.type == .photo {
let displayImage = asset.fullResolutionImage!images?.append(d)
let token = UserDefaults.standard.string(forKey: "newToken")
let image = displayImage
let imgData = image.jpegData(compressionQuality: 0.2)!
let parameters = ["ProjectUnitId": 8568816]
Alamofire.upload(multipartFormData: { multipartFormData in
multipartFormData.append(imgData, withName: "ImageList",fileName: "file.jpg", mimeType: "image/jpg")
for (key, value) in parameters {
multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key)
}
},to:"http://AddProjectUnitImages", headers: [ "Authorization":"Bearer \(String(describing: token))"]) { (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.value)
}
case .failure(let encodingError):
print(encodingError)
}
}
}