Closed jamalahmed1122 closed 2 months ago
Thanks for the report! Could you make a minimum reproduce repo with your issue? It would be very useful and I will be able to fix this issue quickly. Thanks!
I should ask it because we have a many test, including array files loading, validation and so on and these were going to success.
Thanks for the report! Could you make a minimum reproduce repo with your issue? It would be very useful and I will be able to fix this issue quickly. Thanks!
I should ask it because we have a many test, including array files loading, validation and so on and these were going to success.
it seems that all validations will fail if we specified type as an array like this: My DTO:
import { HasMimeType, IsFiles, MemoryStoredFile } from 'nestjs-form-data';
export class FormDataTestDto {
@IsFiles()
@HasMimeType(['image/*'], { each: true })
avatars: MemoryStoredFile[];
}
And it always throws error:
{
"message": "File must be of one of the types image/*",
"statusCode": 400,
"timestamp": "2024-06-22T14:36:59.052Z",
"path": "/api/v1/auth/upload"
}
@minhchi1509 @jamalahmed1122
I updated the Installation section in the readme, please check it out.
Also I created a playground demo for this issue to demo array of files validation based on your dto, please check it:
https://github.com/dmitriy-nz/nestjs-form-data-issue-60-playground
Don't shy away from MR in playgroud to demo your issue
@minhchi1509 @jamalahmed1122 I updated the Installation section in the readme, please check it out. Also I created a playground demo for this issue to demo array of files validation based on your dto, please check it: https://github.com/dmitriy-nz/nestjs-form-data-issue-60-playground Don't shy away from MR in playgroud to demo your issue
Thanks for your playground demo, i have tested and it worked. But when I add option enableImplicitConversion: true
to ValidationPipe(), the validation will fail again:
app.useGlobalPipes(
new ValidationPipe({
transform: true,
transformOptions: { enableImplicitConversion: true },
})
);
I must have that option because it can automatically transform type, such as from type string to number (refer to: https://stackoverflow.com/questions/73238463/nestjs-validationpipetransform-true-does-not-transform-string-to-number-for). Do you have any idea?. Thank you
@minhchi1509 Thank you very much for your help, the issue has been reproduced and fixed in version 1.9.9, it is already deployed to npm, please try it out.
@dmitriy-nz thanks, i have updated the package and it is working fine now, thanks for the awesome package, keep it up.
the below code works perfectly fine:
but when i change areaPhotos from areaPhotos: FileSystemStoredFile; to areaPhotos: FileSystemStoredFile[]; making sure typescript knows it is an array of files, it fails.
in this function
in the library code i have seen that value looks like this π ~ isFile ~ value: [ originalName: 'Screenshot from 2024-06-11 09-44-16.png', encoding: '7bit', busBoyMimeType: 'image/png', path: '/home/jamal/projects/rx-trade-backend/uploads/Screenshot from 2024-06-11 09-44-16-a5fd66.png', size: 320685, fileType: { ext: 'png', mime: 'image/png' } ]
which causes the validation to fail.