我做下面的上傳PNG文件與參數:Alamofire 4上傳與參數
Alamofire.upload(
multipartFormData: { multipartFormData in
multipartFormData.append(UIImagePNGRepresentation(tempImage!)!, withName: "file", fileName: "picture.png", mimeType: "image/png")
// Send parameters
multipartFormData.append((UserDefaults.standard.value(forKey: Email) as! String).data(using: .utf8)!, withName: "email")
multipartFormData.append("png".data(using: .utf8)!, withName: "type")
},
to: "user/picture",
encodingCompletion: { encodingResult in
switch encodingResult {
case .success(let upload, _, _):
upload.responseJSON { response in
debugPrint("SUCCESS RESPONSE: \(response)")
}
case .failure(let encodingError):
self.removeSpinnerFromView()
print("ERROR RESPONSE: \(encodingError)")
}
}
)
問題是,我的服務器上我沒有看到email
和type
表單字段。我遵循這個網上發佈的例子。有什麼我應該做不同的做法嗎?
編輯
如果我刪除,我把部分:
multipartFormData.append(UIImagePNGRepresentation(tempImage!)!, withName: "file", fileName: "picture.png", mimeType: "image/png")
那麼參數都包括在內。否則,我認爲這是Alamofire 4.0.1中的一個錯誤。
請響應。 –