I have a ruby on rails app that takes an image file, "attaches it to a member", and uploads it to s3. When I use insomnia and POST directly to the app ... it works, however when I use the exact same endpoint behind AWS Api Gateway, the image is corrupt and not viewable.
Here is the comparison of the requests.
https://www.diffchecker.com/wwUmpB5W
Something I noticed, is that the paperclip gem is running different commands. It's evident that paperclip realized that the file is not an image when being passed through API gateway.
Here are some potentially relevant screenshots
Here is the rails code:
def create
logger.info 'upload_attachment_api_general_v1'
logger.info params
logger.info request.env
@file = current_merchant.members.find(params[:member_id]).attachments.new(file: params[:file], label: params[:label])
if params[:file] && @file.save
render json: @file
else
render json: @file.errors, status: :unprocessable_entity
end
end
An HTTP proxy integration enables you to connect an API route to a publicly routable HTTP endpoint. With this integration type, API Gateway passes the entire request and response between the frontend and the backend. To create an HTTP proxy integration, provide the URL of a publicly routable HTTP endpoint.
You can integrate an API method with an HTTP endpoint using the HTTP proxy integration or the HTTP custom integration. API Gateway supports the following endpoint ports: 80, 443 and 1024-65535.
To upload a binary file (image) to an S3 bucket using API Gateway, you must activate binary support for your API Gateway REST API. To allow your API to access your S3 bucket, you must also create an AWS Identity and Access Management (IAM) role.
API gateway functions as a reverse proxy to accept all API calls, aggregate the required services, and return the right result. An API gateway has more functionalities than an API proxy, especially in security and monitoring. The Backend for Frontend (BFF) design is commonly used in Microservices development.
I figured it out. The content type is NOT an image/png
... the content type is multipart/form-data
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With