Bird
0
0

Which of the following is the correct way to apply a file validation pipe to a file upload in a NestJS controller?

easy📝 Syntax Q12 of 15
NestJS - Pipes
Which of the following is the correct way to apply a file validation pipe to a file upload in a NestJS controller?
A@UsePipes(new FileValidationPipe()) uploadFile(@UploadedFile() file: Express.Multer.File) {}
B@UseGuards(new FileValidationPipe()) uploadFile(@UploadedFile() file: Express.Multer.File) {}
C@UseFilters(new FileValidationPipe()) uploadFile(@UploadedFile() file: Express.Multer.File) {}
D@UseInterceptors(new FileValidationPipe()) uploadFile(@UploadedFile() file: Express.Multer.File) {}
Step-by-Step Solution
Solution:
  1. Step 1: Identify the correct decorator for validation pipes

    In NestJS, validation pipes are applied using the @UsePipes() decorator.
  2. Step 2: Match the usage with file upload

    The FileValidationPipe is a pipe, so it must be passed inside @UsePipes() to validate the uploaded file.
  3. Final Answer:

    @UsePipes(new FileValidationPipe()) uploadFile(@UploadedFile() file: Express.Multer.File) {} -> Option A
  4. Quick Check:

    Validation pipe = @UsePipes() [OK]
Quick Trick: Use @UsePipes() for validation pipes, not guards or filters [OK]
Common Mistakes:
  • Using @UseGuards or @UseFilters instead of @UsePipes
  • Applying pipes without instantiating them
  • Confusing interceptors with pipes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes