I am trying to upload UIImage file to server by using .post and mulitpartFormData way. Anyone can look at below code and advise what is wrong? I have tried to succeed uploading image file for whole day today. But with my short experience and study of swift, even it was so difficult to research proper answer related to my situation.
PS. "UIImageView.image must be used from main thread only" message are shown continuously "guard let" point. Please also let me borrow your wisdom.
Alamofire.upload(
multipartFormData: { multipartform in
guard let image = self.profileImage.image else { return }
let imageData = UIImageJPEGRepresentation(image, 0.1)
multipartform.append(imageData!, withName: "img_profile", mimeType: "image/jpg")
},
to: urlString,
method: .post,
encodingCompletion: { result in
switch result {
case .success(let request, _, _):
request.responseData(completionHandler: { (response) in
switch response.result {
case .success:
print(response)
case .failure(let error):
print(error)
}
})
case .failure(let error):
print(error)
}
})