[英]Alamofire Image upload with Parameters and AuthToken Header with patch method
這里是我正在使用的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上傳,但似乎沒有一個對我有用嗎? 請幫我在這里找到問題。
重復問題中給出的解決方案對我不起作用
謝謝
您的內容類型有誤。 使用“內容類型”:“multipart / form-data”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.