我试图使用Alamofire进行上传,但返回了一个错误:responseSerializationFailed(Alamofire.AFError.ResponseSerializationFailureReason.inputDataNilOrZeroLength),有人知道这是什么吗?
我的代码:
let image = #imageLiteral(resourceName: "img12345")
let imgData = UIImageJPEGRepresentation(image, 0.2)!
let parameters = ["Cookie": UsersService.get()?.kID]
Alamofire.upload(multipartFormData: { multipartFormData in
multipartFormData.append(imgData, withName: "fileset",fileName: "file.jpg", mimeType: "image/jpg")
for (key, value) in parameters {
multipartFormData.append((value?.data(using: String.Encoding.utf8)!)!, withName: key)
}
},to:"http://\(ServersService.getAtual()!.host)/hnzacerto/HnzAcertoViagemUploader")
{ (result) in
switch result {
case .success(let upload, _, _):
upload.uploadProgress(closure: { (progress) in
print("Upload Progress: \(progress.fractionCompleted)")
})
upload.responseJSON { response in
print(response)
}
case .failure(let encodingError):
print(encodingError)
}
}
谢谢