【发布时间】:2018-11-25 09:34:40
【问题描述】:
这是我正在使用的 alamofire 代码
params 是字典[String:Any]
Alamofire.upload(
multipartFormData: { MultipartFormData in
for (key, value) in params {
if let image = value as? UIImage {
if let imageData = UIImageJPEGRepresentation(image, 0.2) {
MultipartFormData.append(imageData, withName: "image", fileName: "file.jpg", mimeType: "image/jpg")
}
}else {
MultipartFormData.append(String(describing: value).data(using: String.Encoding.utf8)!, withName: key)
}
}
}, to:url, method: .patch, headers: ["token": authToken,"Content-Type":"application/json"]) { (result) in
switch result {
case .success(let upload, _, _):
upload.responseJSON { response in
guard response.result.isSuccess else {
print(response.error?.localizedDescription ?? "Error while requesting")
return
}
if let value = response.result.value {
let json = JSON(value)
}
}
case .failure(let encodingError):
print(encodingError)
}
}
我想将图像上传到服务器,阅读一些通过 alamofire 上传的帖子,但似乎没有一个对我有用? 请帮我在这里找到问题。
重复问题中给出的解决方案对我不起作用
谢谢
【问题讨论】:
-
是的...试过但没有任何效果...你认为服务器可能有问题吗,因为我已经尝试了我遇到的所有问题
-
这是什么...方法:.patch 我对此不太了解..
-
查看这个链接我在这个链接中给出了详细的答案(方法:.post):stackoverflow.com/questions/40262201/…。
标签: ios swift alamofire image-uploading