You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is this feature request related to a new or existing Amplify category?
api
Is this related to another service?
API Gateway
Describe the feature you'd like to request
It seems like having a REST API configured through API Gateway to return binary data is not as easy as one would think.
From what I gathered this is what needs to be done:
Add the binaryMediaType (e.g. application/pdf) in the API Gateway settings via override.ts (e.g. resources.restApi.binaryMediaTypes = ['application/pdf'];)
Add this exact same binary media type to the aws-serverless-express server creation call - (i.e. const server = awsServerlessExpress.createServer( app, null, // binary mime types - this will cause the lambda to base64 encode the response body and return isBase64Encoded=true ['application/pdf'] );). Apparently this is not needed with the latest vendia package.
Make sure the client requesting the binary data has the first entry in its accept header the same as what's specified in binaryMediaTypes. This is ofcourse impossible to control in a straight up browser link. And setting binaryMediaTypes to */* in API Gateway is not a solution as that messes up JSON Rest APIs
Return the binary data and set the content type in the REST API endpoint (res.contentType('application/pdf'); res.send(pdfBuffer))
Describe the solution you'd like
This should at least be documented by amplify cli and perhaps an option to just have amplify cli configure this setting for us, as you need to become an api gateway expert to make this setting work, and even with that there's limitations (if you can't control accept header of client you are out of luck).
Describe alternatives you've considered
Upload the binary data to s3 and do a redirect to a presigned url.
Additional context
No response
Is this something that you'd be interested in working on?
👋 I may be able to implement this feature request
⚠️ This feature might incur a breaking change
The text was updated successfully, but these errors were encountered:
Is this feature request related to a new or existing Amplify category?
api
Is this related to another service?
API Gateway
Describe the feature you'd like to request
It seems like having a REST API configured through API Gateway to return binary data is not as easy as one would think.
From what I gathered this is what needs to be done:
resources.restApi.binaryMediaTypes = ['application/pdf'];
)const server = awsServerlessExpress.createServer( app, null, // binary mime types - this will cause the lambda to base64 encode the response body and return isBase64Encoded=true ['application/pdf'] );
). Apparently this is not needed with the latest vendia package.*/*
in API Gateway is not a solution as that messes up JSON Rest APIsDescribe the solution you'd like
This should at least be documented by amplify cli and perhaps an option to just have amplify cli configure this setting for us, as you need to become an api gateway expert to make this setting work, and even with that there's limitations (if you can't control accept header of client you are out of luck).
Describe alternatives you've considered
Upload the binary data to s3 and do a redirect to a presigned url.
Additional context
No response
Is this something that you'd be interested in working on?
The text was updated successfully, but these errors were encountered: