#@UploadedFile(new myPipe()) doesn't call to the pipe, event doesn't call the pipe constructor
7 messages · Page 1 of 1 (latest)
Pretty sure that was a feature added in nest 8 at the earliest if not nest 9
yep, you are right. But is there a way to do this without the ParseFilePipe feature?
I mean, i just want to call a pipe when I upload a file
The decorator can be imitated with your own decorator
export const UploadedFile = createParamDecorator((data, ctx) => {
return ctx.switchToHttp().getRequest().file;
});
Now pipes should work
hey, that worked, please give a brief explanation of why this worked when you have the chance. Thank you for your worthy help
There are a few param decorators that inherently don't allow for pipes. @Req(), @Header(), and @UploadedFile() are three I can think of immediately.
However, custom decorators do allow for pipes, and as the @UploadedFile() decorator is really just a shorthand for req.file we can recreate it in a way that allows for pipes