Files
main.tsmain
What you'll learn
- Receive one uploaded file with FileInterceptor and @UploadedFile(), and the form's fields with @Body()
- Validate an upload's size and real type with ParseFilePipe, MaxFileSizeValidator and FileTypeValidator
- Receive several files with FilesInterceptor and a maximum count
Press Run tests to start the app. Its log appears here.Graded endpoints
A cat without a photo
FileInterceptor parsed the multipart body: the file reached the handler through the validators, and the caption field arrived in the body
The client said image/png; the bytes have no PNG signature, and FileTypeValidator believes the bytes. The message repeats the type the client claimed
MaxFileSizeValidator runs first and names both sizes
The form carried a caption and no photo; ParseFilePipe requires one
A file in a field the interceptor did not ask for is multer's Unexpected field
The row remembers the file's name, size and type
FilesInterceptor collected both files from the same field
maxCount is two; the third is an Unexpected field