更新的Alamofire 4.0.0没有提到如何使用Httpmethod&使用multipartFormData上传的Httpheaders.这就是我google并在stackoverflow问题中找到解决方案的原因.但问题是我做了同样的回答然后得到以下错误消息和建设失败.请帮我解决一下.
Type of expression is ambiguous without more context
这是我的编码:
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( _): } } )
Alamofire.upload(multipartFormData:to:encodingCompletion :)对于to:参数采用URLConvertible.相反,你应该使用Alamofire.upload(multipartFormData:with:encodingCompletion :),它带有一个URLRequestConvertible,带有:参数.
原文链接:https://www.f2er.com/swift/319512.html我认为URL的参数名称与URL()类型相同有助于创建奇怪的编译器错误.
以下编译对我来说:
let url = try! URLRequest(url: URL(string:"www.google.com")!,headers: nil) Alamofire.upload( multipartFormData: { multipartFormData in multipartFormData.append(Data(),with: url,_): upload.responseJSON { response in if((response.result.value) != nil) { } else { } } case .failure( _): break } } )