The type of expression is ambiguous without additional context in Alamofire.upload swift 3

Updated Alamofire 4.0.0 does not mention how to put Httpmethod and Httpheaders in upload with multipartFormData. This is why I google and found a solution in this stackoverflow question. But the problem is that I did the same as this answer, after which I received the following error message, and the creation failed. Please help me how to solve it.

The type of expression is ambiguous without additional context.

Here is my coding:

let URL = try! URLRequest(url: Config.imageUploadURL, method: .post, headers: headers) Alamofire.upload( multipartFormData: { multipartFormData in multipartFormData.append(self.imageData, withName: "image", fileName: "file.png", mimeType: "image/png") }, to: URL, encodingCompletion: { encodingResult in switch encodingResult { case .success(let upload, _, _): upload.responseJSON { response in if((response.result.value) != nil) { } else { } } case .failure( _): } } ) 
+8
swift swift3 xcode8 alamofire
source share
3 answers

Alamofire.upload(multipartFormData:to:encodingCompletion:) accepts a URLConvertible for the argument to: Instead, you should use Alamofire.upload(multipartFormData:with:encodingCompletion:) , which takes a URLRequestConvertible for its with: argument.

I think your URL argument name, which is the same as the type of URL() , helps create weird compiler errors.

The following compilation for me:

 let url = try! URLRequest(url: URL(string:"www.google.com")!, method: .post, headers: nil) Alamofire.upload( multipartFormData: { multipartFormData in multipartFormData.append(Data(), withName: "image", fileName: "file.png", mimeType: "image/png") }, with: url, encodingCompletion: { encodingResult in switch encodingResult { case .success(let upload, _, _): upload.responseJSON { response in if((response.result.value) != nil) { } else { } } case .failure( _): break } } ) 
+12
source share

For me, the build error was caused by multipartFormData.appendBodyData() . After replacing it with multipartFormData.append() problem was resolved.

0
source share

I got the same error after spending a lot of time, I found that the problem was:

I skipped MutableURLRequest instead of passing the URLRequest object. That is why I got this error. After he typed the URLRequest value, it will start working.

0
source share

All Articles