Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store and send image content-type #57

Open
oliverjam opened this issue Feb 4, 2022 · 0 comments
Open

Store and send image content-type #57

oliverjam opened this issue Feb 4, 2022 · 0 comments

Comments

@oliverjam
Copy link

model.getImg(req.params.id).then((user) => {
res.send(user.img);
});

Right now you just send the raw bytes of the image to the browser. Browsers are smart enough to interpret these as images, but if you look in the network tab you'll see all the image requests on /news-feed are just octet-stream (instead of e.g. png or image/jpeg or something.

It's best practice to let the browser know exactly what you're giving it. There are different optimisations and other behaviours that might happen for different types of image decoding that presumably cannot happen here.

Multer provides you with the mimetype of the uploaded file, so you could store this (and file size/any other info you might need) in the DB along with the raw bytes. Then you'd use this info to set the content-type header (and maybe content-length etc)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant