我正在构建一个使用非常受欢迎的AlamoFire HTTP Library上传图片的应用iOS;这是代码:
let headers: HTTPHeaders = ["Accept": "application/vnd.apple.pkpass; application/json"]
Alamofire.upload(profileImageData, to: "the-endpoint"), method: .post, headers: headers)
.uploadProgress { progress in
print("Upload progress: \(progress.fractionCompleted)")
}.downloadProgress { progress in
print("Download progress: \(progress.fractionCompleted)")
}.responseData { response in
print("--> do something response")
}
注意
profileImageData
的格式为Swift Data。
如果我设置"-endpoint"直接POST到我的服务器,一切正常。发生了一些处理,图像保存到S3就好了。
但是,如果我设置"-endpoint"要使用AWS API网关,事情会变得很糟糕。
具体来说,保存到S3的图像已损坏且无法观看。在检查时,最让我印象深刻的是请求大小的显着差异。
我希望这与AlamoFire发布application/x-www-form-urlencoded
的事实有关......但我不知道该怎么做。我对API网关很陌生,所以我真的卡住了。
如果我能提供帮助诊断我做错的事情,请告诉我。
答案 0 :(得分:0)
我能够通过reading the docs ...来解决这个问题。具体来说,我将application/x-www-form-urlencoded
添加为Binary Media Type
,并将Method Request
和Integration Request
设置为直接通过内容。