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
118 stars 23 forks source link

image/svg+xml mimetype converting into application/xml #61

Open VarshaJatav opened 3 weeks ago

VarshaJatav commented 3 weeks ago

I am using HasMimeType decorator of 'nestjs-form-data' in dto. @HasMimeType([ 'image/bmp', 'image/gif', 'image/jpeg', 'image/png', 'image/webp', 'image/svg+xml', ])

When uploading the svg file of mime type 'image/svg+xml', I was getting validation error of mimetype. Error message -> "File must be of one of the types image/bmp, image/gif, image/jpeg, image/png, image/webp, image/svg+xml"

I tried to check the mimetype of image by commenting this decorator, so I found that it was converting the mimetype 'image/svg+xml' to 'application/xml' which violates the validations.

Console message of the file uploaded -> FileSystemStoredFile { originalName: 'image.svg', encoding: '7bit', busBoyMimeType: 'image/svg+xml', path: '/home/Documents/project/image.svg', size: 100314, fileType: { ext: 'xml', mime: 'application/xml' } }

This is problematic as we are using the fileType.ext extension to save the file to our database and when this is streamed, the image is unrenderable as the path now refers to a file with extension .xml instead of the correct .svg.

VarshaJatav commented 3 weeks ago

@dmitriy-nz Please look into this