I am trying to upload image with multiple parameters using alamofire multipart with swift 4 but I can not upload image sucessfully and I got response like
{
"error" : "error uploading file, please retry"
}
Here is my function which I call on upload button event.
// selectedLogo = (info["UIImagePickerControllerOriginalImage"] as? UIImage)!
let imageData = UIImageJPEGRepresentation(selectedLogo, 1.0)
let parameters: Parameters = ["id": strUserId,
"telephone": self.txtTelephoneNumber.text!,
"email": self.txtEmail.text!,
"notice":self.txtNotices.text!,
"status" : userData["status"]]
print(parameters)
Alamofire.upload(multipartFormData: { (multipartFormData) in
if let data = imageData{
multipartFormData.append(data, withName: "club_image", fileName: "file.jpg", mimeType: "image/jpg")
}
for (key, value) in parameters {
multipartFormData.append("\(value)".data(using: String.Encoding.utf8)!,withName: key as String)
}
}, to:"\(self.app.strBaseAPI)updatedata.php")
{ (result) in
switch result {
case .success(let upload, _, _):
upload.uploadProgress(closure: { (progress) in
//Print progress
print(progress)
})
upload.validate()
upload.responseJSON { response in
if response.response?.statusCode == 200
{
if response.result.isSuccess == true
{
if let value = response.result.value
{
self.json = JSON(value)
print(self.json)
let strStatus : String = self.json["success"].stringValue
if strStatus == "true"
{
Toast(text: strStatus).show()
}else{
Toast(text: strStatus).show()
}
}else{
Toast(text: "Something wrong").show()
}
}else{
Toast(text: "Something wrong").show()
}
}else{
SVProgressHUD.dismiss()
Toast(text: "Something wrong").show()
}
}
case .failure(let encodingError):
//print encodingError.description
print(encodingError.localizedDescription)
}
when I convert image using UIImagePNGRepresentation with same method just change one line
multipartFormData.append(imageData!, withName: "image", fileName: "image.png", mimeType: "image/png")
it will give me like this
SUCCESS: {
error = "error data post";
}
Please help me!!