Node.js / NestJS

File Upload

Multer, file validation, storage, streaming, S3 integration, file size limits

15 gespreksvragen·
Mid-Level
1

Which package to use for handling file uploads in NestJS?

Antwoord

NestJS uses Multer via @nestjs/platform-express to handle multipart/form-data uploads. Multer is integrated by default with NestJS Express platform. It provides decorators like @UseInterceptors(FileInterceptor()) to simplify uploads. Express-fileupload and body-parser are not recommended with NestJS.

2

How to upload a single file in a NestJS endpoint?

Antwoord

FileInterceptor('file') is the decorator for uploading a single file, where 'file' is the form field name. FilesInterceptor is for multiple files from the same field, FileFieldsInterceptor for multiple different fields. @UploadedFile() alone doesn't work without an interceptor.

3

How to upload multiple files from the same field in NestJS?

Antwoord

FilesInterceptor('files', 10) allows uploading up to 10 files from the 'files' field. The second parameter limits the number of files. FileInterceptor is for a single file, AnyFilesInterceptor for all fields without limit, and multiplying FileInterceptor doesn't work.

4

How to validate the MIME type of an uploaded file in NestJS?

5

How to limit an uploaded file size to 5 MB in NestJS?

+12 gespreksvragen

Beheers Node.js / NestJS voor je volgende gesprek

Krijg toegang tot alle vragen, flashcards, technische tests, code review-oefeningen en gespreksimulatoren.

Begin gratis