anacronw / multer-s3

multer storage engine for amazon s3
MIT License
660 stars 190 forks source link

Content-Type cannot be detected from a text/plain file #160

Closed mytharcher closed 2 years ago

mytharcher commented 2 years ago

I have a text/plain file a.txt which contains only a string as hello world!. But the fileType function only got null result for this file. Not sure if it is a bug from file-type@^3.x (and latest is @17.x).

Maybe 2 ways could solve:

  1. Use the file stream's own mimetype if exists.
  2. Upgrade package file-type's version to latest and test.
LinusU commented 2 years ago

This is not supported by file-type, and probably won't be: https://github.com/sindresorhus/file-type/issues/55

You can provide a custom function that e.g. falls back to the browser reported file type, but I don't think that we should change the default to that since there is no guarantee that the uploaded file actually is text just because the header said so.

https://github.com/anacronw/multer-s3#setting-custom-content-type