swift - 图片未上传,而 API 调用(通过 PATCH 方法)成功,Alamofire,Swift
问题描述
我想使用在补丁方法上运行的 API 将图像上传到服务器,API 还需要一个身份验证令牌。
Alamofire.upload(
multipartFormData: { MultipartFormData in
for (key, value) in params {
if let image = value as? UIImage {
if let imageData = UIImageJPEGRepresentation(image, 0.7) {
MultipartFormData.append(imageData, withName: "image", fileName: "file\(arc4random()).jpg", mimeType: "image/jpeg")
}
}else {
MultipartFormData.append(String(describing: value).data(using: String.Encoding.utf8)!, withName: key)
}
}
}, to:url, method: .patch, headers: ["content-type":"application/json","token": authToken]) { (result) in
switch result {
case .success(let upload, _, _):
upload.responseJSON { response in
guard response.result.isSuccess else {
print(response.error?.localizedDescription ?? "Error while requesting")
completionHandler(nil)
return
}
if let value = response.result.value {
let json = JSON(value)
print(json)
}else {
completionHandler(nil)
}
}
case .failure(let encodingError):
print(encodingError)
}
}
问题是API
调用成功但图片没有上传到服务器上,请帮帮我。
谢谢
解决方案
推荐阅读
- python - 将除以零解释为 nan
- python - 获取 3D 对象网格上的像素坐标(python)
- ios - 故事板中的安全区域错位
- angular - 重新加载部署在 tomcat 服务器上的 Angular 应用程序时出现 404 错误
- ios - 无法在 swift iOS 中处理 http 代码?
- android - ITelephony.endCall() 不再用于阻止 Android 8/Android O/API 26 中的呼叫
- amazon-web-services - 如何根据其中运行的容器动态修改正在运行的ECS实例的安全组?
- android - Android临时保存图像并在不再删除图像时的最佳实践?
- vb.net - 当其中一个文本框未填写时,程序不断崩溃
- java - 无法使用 netbeans 添加或更新父行