app.use("/uploads", express.static("./server/uploads"));
Everytime I access http://localhost:4500/uploads/16562754008013gncm1.jfif , it automatically downloads
-index.js
-server
----uploads
-------16562754008013gncm1.jfif
CodePudding user response:
It may be that part of your problem is that .jfif
is perhaps a file extension that Express and the browser don't know and recognize so the only thing a browser knows to do with it is offer a download dialog in the browser. You can verify this by looking in the network tab of the Chrome/Edge or Firefix inspector and look at what the content-type is set to when the response comes back from the server.
If Express recognizes the file extension, it will set the appropriate content-type. And, if the browser recognizes the content-type, it will treat it appropriately. If not, Express will set a generic content-type and the browser won't know what to do with it other than offering a download dialog.
You can fix that by either giving the file a file extension that is generally known that corresponds to its actual type or you can manually override and set the content-type (if that content-type is something that the browser recognizes).