- Neueste
- Die meisten Stimmen
- Die meisten Kommentare
First step would be to make sure it is not a CORS issue. Please take a look at this document from AWS Premium Support on how to debug CORS issues - https://aws.amazon.com/premiumsupport/knowledge-center/api-gateway-cors-errors/
Also please take a look at the instructions on this document to ensure you are following all the steps involved in handling binary data correctly in your API Gateway assuming you are using REST APIs - https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-payload-encodings-configure-with-control-service-api.html
If you are using HTTP APIs instead of REST APIs in AWS API Gateway, please follow the instructions here - https://aws.amazon.com/blogs/compute/handling-binary-data-using-amazon-api-gateway-http-apis/
This article is also helpful - https://aws.amazon.com/premiumsupport/knowledge-center/api-gateway-binary-data-lambda/
I feel like I should come back and answer this question in case someone in the future (probably even me) comes across it. The underlying issue was problems with the encoding type that was being returned by the API Gateway. All the errors I listed were side errors having to do with OPTIONS requests that weren't needed but were automatically created when I set up CORS (my API and UI are on different subdomains, which I know if I had set it up on the first one, it would have never needed CORS to being with).
Within my API Gateway Settings, I did set Binary Media Types to include application/pdf
and I did add headers to my initial API request from the UI with 'Content-Type': 'application/json', 'Accept': 'application/pdf'
. The final issue had to do with how I was setting up the serverless deploy. My API was exporting module.exports.handler = serverless(app)
but needed an additional configuration options that ended up looking like this:
module.exports.handler = serverless(app, {
binary: ['application/pdf', 'application/json']
});
After deploying that to my Lambda being served by API Gateway, this ended up resolving the issue and I was able to stream a generated PDF to the end-user.
Relevanter Inhalt
- AWS OFFICIALAktualisiert vor 2 Jahren
- AWS OFFICIALAktualisiert vor einem Jahr
I appreciate your response. I updated the status of my question. So I removed the OPTIONS method from my API Gateway which surprisingly all three of my listed errors, however it still returns what appears to be a blank or corrupted PDF. Though this functionality works fine locally and through a testing suite. I have application/pdf set as an a binary type in the API Gateway settings, and testing it through Insomnia, I set an Accept header with / for testing purposes. Unfortunately, the PDF still returns blank. I get the same result when I use the Test function within API Gateway but can confirm the PDFs generate properly locally. I have read over those articles and it looks like I have tried a lot of what they are suggesting.