Closed aribambang closed 2 years ago
You know, linking to our own code isn't a minimum reproduction.
I'm surprised this happens rather than multer throwing an exception as interceptors are triggered before pipes.
Please provide a minimum reproduction repository (Git repository/StackBlitz/CodeSandbox project).
You know, linking to our own code isn't a minimum reproduction.
I'm surprised this happens rather than multer throwing an exception as interceptors are triggered before pipes.
Please provide a minimum reproduction repository (Git repository/StackBlitz/CodeSandbox project).
i'm sorry, I have updated the minimum reproduction.
Okay, I can confirm that multer only cares about the field existing, not necessarily that there is a file to parse there. We should probably add a FileExistsValidator
that we prepend to the array if there are validators to be ran
cc @thiagomini
I'll have a look on that and work in a fix asap, thanks for reporting!
@kamilmysliwiec Created a PR with the fix for this issue, would appreciate your review on that
I'm dealing with the same issue as this, where I have an optional file upload field. While PR seems like a good solution, is there any way to use the ParseFilePipeBuilder
manually in the controller? So that I can catch the errors myself?
@Post('/')
@UseInterceptors(FileInterceptor('logo'))
public async save(
@Body() body: SettingsDto,
@UploadedFile() file: any,
@Res() res: Response,
) {
try {
// How would I use ParseFilePipeBuilder here?
new ParseFilePipeBuilder()
.addFileTypeValidator({
fileType: 'ico'
})
.addMaxSizeValidator({
maxSize: 50000
})
.build()
} catch(err) {
return res.render('/views/settings.pug', { errror: err.message })
}
}
Let's track this here https://github.com/nestjs/nest/pull/10025
Is there an existing issue for this?
Current behavior
i'm uploading image file using form-data, when i don't attach file then in ParseFilePipeBuilder function i get error
ERROR [ExceptionsHandler] Cannot read properties of undefined (reading 'size')
Minimum reproduction code
https://stackblitz.com/edit/nestjs-typescript-starter-amuib7
Steps to reproduce
No response
Expected behavior
We must to create a validation function on
ParseFilePipeBuilder
when the file doesn't exist during upload.Package
Other package
No response
NestJS version
9.0.5
Packages versions
Node.js version
No response
In which operating systems have you tested?
Other
No response