Reputation: 12342
I got NodeJS application running on AWS Lambda + API gateway environment.
I am deploying my app via serverless app (https://www.npmjs.com/package/serverless). My assets (including images) are packed together to zip format, sent to S3 storage and deployed via cloudfront (regular serverless flow).
Requests to images responses with 200 OK status. The problem is that they are not displaying. I have no idea where should I start to look for an issue.
I enabled binary media types in my API Gateway, and provided following types: image/gif
, image/jpeg
.
For example I am trying to display this image: http://www.top13.net/wp-content/uploads/2015/10/perfectly-timed-funny-cat-pictures-5.jpg
Here is URL to it in my app: http://angular-universal-serverless.maciejtreder.com/assets/img/cat.jpg
Is it even possible to display images this way? Maybe I should upload them to S3 storage?
Here are some entries from logs (before enabling binary media types):
http://www.heypasteit.com/clip/0IILRO
and after enabling: http://www.heypasteit.com/clip/0IILS2
Upvotes: 1
Views: 619
Reputation: 329
I had this problem on Angular 12.0.5
using regular angular-universal (ng add @nguniversal/express-engine
), serverless
and @vendia/serverless-express
.
The solution was:
1 - Add the media types in the API Gateway:
2 - Add apiGateway.binaryMediaTypes
on my serverless.yml
file:
provider:
...
apiGateway:
binaryMediaTypes:
- '*/*'
Upvotes: 1
Reputation: 12342
I have solved problem, by my own.
Here is boilerplate repository: https://github.com/maciejtreder/angular-universal-serverless
The point was to encode files on Lambda side, and send it in encoded form to API GW with proper headers.
Upvotes: 1