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
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)
The text was updated successfully, but these errors were encountered:
week4-milly-paolo-orian/routes/imgPath.js
Lines 4 to 6 in ff05340
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 justoctet-stream
(instead of e.g.png
orimage/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 thecontent-type
header (and maybecontent-length
etc)The text was updated successfully, but these errors were encountered: