Alamofire(Swift 3):对成员“上传(..”)的模糊引用
Posted
技术标签:
【中文标题】Alamofire(Swift 3):对成员“上传(..”)的模糊引用【英文标题】:Alamorefire(Swift 3) : Ambiguous reference to member 'upload(..' 【发布时间】:2016-10-19 08:07:31 【问题描述】:我将Alamorefire
用于Swift 3
,但出现错误:Ambiguous reference to member 'upload
。
这是我的代码:
Alamofire.upload(
.post,
url,
multipartFormData: multipartFormData in
// import parameters
for i in 0 ..< params.count
for (key, value) in params[i]
multipartFormData.appendBodyPart(data: value.dataUsingEncoding(NSUTF8StringEncoding)!,
name: key)
// import image to request
multipartFormData.appendBodyPart(data: imageData,
name: "file",
fileName: "file.jpg",
mimeType: "image/jpeg")
,
encodingMemoryThreshold: SessionManager.multipartFormDataEncodingMemoryThreshold,
encodingCompletion: encodingResult in
switch encodingResult
case .Success(let upload, _, _):
upload.responseJSON response in
debugPrint(response.result)
case .Failure(let encodingError):
print(encodingError)
)
我的代码有什么问题?
【问题讨论】:
请回复我的回答。 我遇到了同样的问题。我的问题是我试图为“headers”参数传递[String : String]
字典。我通过写HTTPHeaders(myDictionary)
将字典显式转换为HTTPHeaders
解决了这个问题。
【参考方案1】:
试试下面的代码
Alamofire.upload(multipartFormData: (multipartFormData) in
multipartFormData.append(UIImageJPEGRepresentation(self.photoImageView.image!, 0.5)!, withName: "photo_path", fileName: "swift_file.jpeg", mimeType: "image/jpeg")
for (key, value) in parameters
multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key)
, to:"http://server1/upload_img.php")
(result) in
switch result
case .success(let upload, _, _):
upload.uploadProgress(closure: (Progress) in
print("Upload Progress: \(Progress.fractionCompleted)")
)
upload.responseJSON response in
//self.delegate?.showSuccessAlert()
print(response.request) // original URL request
print(response.response) // URL response
print(response.data) // server data
print(response.result) // result of response serialization
// self.showSuccesAlert()
//self.removeImage("frame", fileExtension: "txt")
if let JSON = response.result.value
print("JSON: \(JSON)")
case .failure(let encodingError):
//self.delegate?.showFailAlert()
print(encodingError)
【讨论】:
这个答案提供了一段与问题中完全不同的代码,它没有解释原始代码的实际错误。以上是关于Alamofire(Swift 3):对成员“上传(..”)的模糊引用的主要内容,如果未能解决你的问题,请参考以下文章
使用 Swift 3 的 Alamofire 4.0 出现“没有成员”错误
Alamofire 4 swift 3 上传带有标题的 MultipartFormData 未发布