dmitriy-nz / nestjs-form-data

NestJS middleware for handling multipart/form-data, which is primarily used for uploading files.
https://www.npmjs.com/package/nestjs-form-data
MIT License
117 stars 23 forks source link

FormReader reads wrong mimetype from stream #37

Closed julianpoemp closed 1 year ago

julianpoemp commented 1 year ago

The loadFile() function in FormReader.ts reads a wrong mime type from a stream. In my case it's audio/vnd.wave instead of audio/wave. That leads to a failing HasMimeType validation.

Bildschirmfoto 2022-09-16 um 14 21 27

I assume it's a bug from the file-type package. You are using an old version, v16.5.4, perhaps this issue is solved if you upgrade to the latest version?

I tested it uploading a file using FileSystemStorage and a DTO that uses the HasMimeTypedecorator. I'm currently using nestjs-form-data@1.8.3 and NestJS@9.0.11 with platform-express@9.0.11

As a workaround I downgraded back to nestjs-form-data@1.7.1.

dmitriy-nz commented 1 year ago

Hi! Can you confirm that the new version detects the correct mime type for your file?

julianpoemp commented 1 year ago

@dmitriy-nz can't create a custom build of nestjs-form-data with the latest file-type package. Building with npm run build doesn't create a valid package. The build can't be installed via npm link or as archive in my project.

julianpoemp commented 1 year ago

@dmitriy-nz found a way to create valid packages (using npm pack).

There is a huge ESM problem with file-type imports in commonjs packes so I can't use the latest version because I get the error as described here . There are a lot of issues discussed in file-type where a lot of people don't recommend to update it as long as you are using commonjs. I think this will be an issue in the future.

Furthermore I found out that the "correct" mime types for audio/wave and audio/x-wave should be audio/vnd.wave according to this PR. So I changed the valid mime types an my side and now it works.