Ryan Bigg Ryan Bigg - 2 months ago 15
Swift Question

Expression type '()' is ambiguous without more context

I'm trying to do an upload with Alamofire using this code (where photo.image is a UIImage)

let imageData = UIImageJPEGRepresentation(photo.image, 1.0)

Alamofire.upload(
multipartFormData: { multipartFormData in
multipartFormData.append(data: imageData!, withName: "unicorn")
},
to: "https://httpbin.org/post",
encodingCompletion: { encodingResult in
switch encodingResult {
case .success(let upload, _, _):
upload.responseJSON { response in
debugPrint(response)
}
case .failure(let encodingError):
print(encodingError)
}
}
)


However, this tells me "Expression type '()' is ambiguous without more context.

I am not sure what I'm doing wrong here and would love some advice.

Answer

I had the wrong arguments for multipartFormData. Here's what worked:

multipartFormData: { multipartFormData in
                    multipartFormData.append(imageData!, withName: "photo", fileName: "image.jpg", mimeType: "image/jpg")
                },
Comments