Bird
0
0

What will happen when this FileValidationPipe processes a file larger than 1MB?

medium📝 Predict Output Q5 of 15
NestJS - Pipes
What will happen when this FileValidationPipe processes a file larger than 1MB?
transform(file) {
  if (file.size > 1024 * 1024) {
    throw new BadRequestException('File too large');
  }
  return file;
}
AThe pipe throws a BadRequestException with message 'File too large'.
BThe pipe silently ignores the size and returns the file.
CThe pipe logs a warning but returns the file.
DThe pipe returns null without throwing an error.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the size check

    The pipe checks if file.size exceeds 1MB (1024 * 1024 bytes).
  2. Step 2: Behavior on size violation

    If the file is too large, it throws a BadRequestException with the message 'File too large'.
  3. Step 3: Return value if valid

    If the file size is within limits, it returns the file object.
  4. Final Answer:

    The pipe throws a BadRequestException with message 'File too large'. -> Option A
  5. Quick Check:

    Throw exception on invalid file size [OK]
Quick Trick: Throw exception when file size exceeds limit [OK]
Common Mistakes:
  • Not throwing an exception on invalid size
  • Returning null instead of throwing
  • Logging instead of throwing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes