Images not served properly
See original GitHub issueI’m using app.use('/static', express.static(ENV.STATIC_DIR))
to serve PNG and ICO files.
The files are served but not displayed, seems to have the correct Content-Type but are blank (black rectangle).
The “Response” tab in the Chrome Network view shows binary text (usually this is blank for correctly served images), so I’m guessing there’s an encoding issue but I haven’t experienced this before with Express.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:15
Top Results From Across the Web
Images not served properly · Issue #104 · vendia/serverless ...
I'm using app.use('/static', express.static(ENV.STATIC_DIR)) to serve PNG and ICO files. The files are served but not displayed, ...
Read more >How to Fix Images Not Loading in Chrome - Online Tech Tips
If you find the browser doesn't display images for a site, that site may be experiencing problems serving pictures.
Read more >7 Reasons Why Images Are Not Loading on Your Website
Website images fail to load for one of these seven common reasons.
Read more >Angular image not served properly from nodejs backend
I want to serve a image from my nodejs backend and show it in frontend, my backend running at 8081 port and frontend...
Read more >Serve images with correct dimensions - web.dev
Run the Performance Audit (Lighthouse > Options > Performance) and look for the results of the Properly size images audit.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @brettstack, thanks for your response.
#1. Yes I’m doing that.
#2. I’m using
serverless.yml
so this doesn’t make sense to me. However, I have tried adding*/*
andimage/*
,image/png
in the the “Binary Support” tab of the API Gateway console. This doesn’t seem to make any difference.NOTE: the IMG response shows up with the right
content-type
and thex-amzn-remapped-content-length
header matches the original field’s size in bytes, but thecontent-length
is wrong (bigger) so my guess is an encoding issue?NOTE: If I request the resource via postman explicitly setting the “Accept” header to “image/png” then the correct response is received.
I.e., the following returns the correct data:
But, this returns what I think is base64 encoded data:
I have tried adding “binary support” in the API gateway console (the browser (chrome) sends the appropriate
accept
headerimage/webp,image/apng,image/*,*/*
but not explicitlyimage/png
. In fact, if the header doesn’t exactly START withimage/png
, then the wrong encoding is used.Changing the “integration request” config for my
/img/
path doesn’t help either.(BTW, I spent a couple of hours trying to debug this with an AWS specialist – who was really helpful – but we can’t figure out why the Accept header isn’t respected.)
Hi @richburdon there are many issues documenting how to serve binary. It mainly boils down to 2 things:
awsServerlessExpress.createServer(app, null, ['image/png'])