0
下面的代碼在Swift 3中完美地將上傳圖像文件作爲多部分。不過,我還沒有能夠獲得類似於Swift 2.2中的工作。如果我嘗試在Swift 2.2中使用它,我會收到消息Ambiguous reference to member 'upload(_:_:headers:file:)'
模糊引用成員上傳(_:_:headers:file :)'
有沒有辦法在Swift 2.2中完成同樣的事情?我已經找到了幾個相關的問題,但只發現斯威夫特3.工作方案
func submitFile(entryId: Int, entryDetailValue: String, fieldId: Int, fieldType: String) {
let parameters = [
"entryId": "\(entryId)",
"entryDetail": entryDetailValue,
"fieldId": "\(fieldId)",
"type": fieldType
]
print(parameters)
Alamofire.upload(multipartFormData: { (multipartFormData) in
multipartFormData.append(UIImageJPEGRepresentation(self.imageView.image!, 1)!, withName: "file", fileName: "swift_file.jpeg", mimeType: "image/jpeg")
for (key, value) in parameters {
multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key)
}
}, to:"<my endpoint url>")
{ (result) in
switch result {
case .success(let upload, _, _):
upload.uploadProgress(closure: { (progress) in
//Print progress
print(progress)
})
upload.responseData { response in
print(response.result)
}
case .failure(let error):
print(error)
}
}
}
我認爲OP希望在雨燕2.2的解決方案... – hg8