#@UploadedFile(new myPipe()) doesn't call to the pipe, event doesn't call the pipe constructor

7 messages · Page 1 of 1 (latest)

cursive lily
#

Hi everyone! I have this problem, when I consume the endpoint I just get the file information on the console; but the pipe is never called.

"@nestjs/common" version is "^7.5.1", so I can't use the ParseFilePipe

versed glacier
#

Pretty sure that was a feature added in nest 8 at the earliest if not nest 9

cursive lily
#

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

versed glacier
#

The decorator can be imitated with your own decorator

export const UploadedFile = createParamDecorator((data, ctx) => {
  return ctx.switchToHttp().getRequest().file;
});

Now pipes should work

cursive lily
#

hey, that worked, please give a brief explanation of why this worked when you have the chance. Thank you for your worthy help

versed glacier
#

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