swift - 图片上传不起作用,iOS Swift Multipart
问题描述
我必须将图像上传到服务器,但出现异常行为,
if let imgdata = UIImageJPEGRepresentation(#imageLiteral(resourceName: "vishal"), 0.2) {
let headers: HTTPHeaders = [
"token": authToken,
"Content-type": "multipart/form-data"
]
Alamofire.upload(multipartFormData: { (multipartFormData) in
multipartFormData.append(imgdata, withName: "image", fileName: "image.png", mimeType: "image/png")
}, usingThreshold: UInt64.init(), to: url, method: .patch, headers: headers) { (result) in
switch result{
case .success(let upload, _, _):
upload.responseJSON { response in
print("Succesfully uploaded")
if let _ = response.error{
return
}
if let value = response.result.value {
let json = JSON(value)
print(json)
}
}
case .failure(let error):
print("Error in upload: \(error.localizedDescription)")
}
}
}
在一个新项目中,此代码工作正常并将图像上传到服务器,但在我的旧项目中相同代码,api调用成功但图像未上传
请帮忙
解决方案
推荐阅读
- javascript - Java:未调用文本字段onkeydown上if-else条件下的Javascript方法
- javascript - 删除类型脚本中的 Json Key
- c# - 从 xamarin 调用文件上传服务不起作用
- php - php mysql join 查询别名
- html - 正确划分每个图像的图像和文本
- visual-studio-code - Flutter:具有@override 列表的 VSCode 快捷方式
- linux - Local CircleCI 报告“意外的环境准备错误:查找自身容器 id 时出错:为外部容器找到多个 cgroup”
- mysql - R dbplyr WHERE 子句 cp1250 字符集
- java - java - 如何在java中有效地分配工作
- javascript - Javascript 获取 API