我无法将图像上传到服务器。显示上传进度, upload.uploadProgress但之后upload.responseJSON是nil错误。我已尽力而为,但无法解决问题。请任何人都可以帮助我。我究竟做错了什么?当我调试它的{ (result) in switch result {结果无效。
邮递员密钥:( 参数)
ImageList -- for images
ProjectUnitID -- 8568816
SWIFT代码:
if asset.type == .photo {
let displayImage = asset.fullResolutionImage!
images?.append(d)
let token = UserDefaults.standard.string(forKey: "newToken")
let image = displayImage
let imgData = image.jpegData(compressionQuality: 0.2)!
let parameters = ["ProjectUnitId": 8568816]
Alamofire.upload(multipartFormData: { multipartFormData in
multipartFormData.append(imgData, withName: "ImageList",fileName: "file.jpg", mimeType: "image/jpg")
for (key, value) in parameters {
multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key)
}
},
to:"http://AddProjectUnitImages", headers: [ "Authorization":"Bearer \(String(describing: token))"])
{ (result) in
switch result {
case .success(let upload, _, _):
upload.uploadProgress(closure: { (progress) in
print("Upload Progress: \(progress.fractionCompleted)")
})
upload.responseJSON { response in
print(response.result.value)
}
case .failure(let encodingError):
print(encodingError)
}
}
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。