Search code examples
alamofireaws-api-gateway

API Gateway adding size to POST?


I'm building an app iOS that uses the very-popular AlamoFire HTTP Library to upload an image; here's the code:

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")
    }

Note profileImageData is in the form of Swift Data.

  • If I set "the-endpoint" to directly POST to my server, everything works. Some processing occurs and the image gets saved to S3 just fine.

  • If, however, I set "the-endpoint" to use an AWS API Gateway, things get wonky.

Specifically, the image saved to S3 is damaged and unviewable. On inspection, what strikes me the most is the very significant difference in the size of the request.

I expect this has to do something with the fact that AlamoFire is posting application/x-www-form-urlencoded ... but I don't know what to do. I'm pretty new to API Gateway, so I'm really stuck.

Please let me know if I can provide something to help diagnose what I'm doing wrong.

Diffs


Solution

  • I was able to solve this by reading the docs .... Specifically, I added application/x-www-form-urlencoded as a Binary Media Type and set the Method Request and Integration Request to simply passthrough the content.