API网关为POST添加大小?

时间:2018-02-23 22:07:24

标签: alamofire aws-api-gateway

我正在构建一个使用非常受欢迎的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网关很陌生,所以我真的卡住了。

如果我能提供帮助诊断我做错的事情,请告诉我。

Diffs

1 个答案:

答案 0 :(得分:0)

我能够通过reading the docs ...来解决这个问题。具体来说,我将application/x-www-form-urlencoded添加为Binary Media Type,并将Method RequestIntegration Request设置为直接通过内容。