Nestjs File Uploads
ASecurityDo not trust the filename or the client-provided `Content-Type`. Set a Multer size limit and inspect the file's magic bytes with `file-type`/`mmmagic` before accepting it. ```ts @Post() @UseInterceptors(FileInterceptor('file', { limits: { fileSize: 5_000_000 } })) upload(@UploadedFile() file: Express.Multer.File) { const detected = await fileTypeFromBuffer(file.buffer); if (!detected || !['image/png', 'image/jpeg', 'application/pdf'].includes(detected.mime)) { throw new BadRequestException('U...
- 584 stars
- 0 votes
- 0 copies
- 3 views
- Added September 5, 2026
Works with
Security analysis
100/100Pro scans all 11 files and shows the line behind each finding
npx -y skills add HoangNguyen0403/agent-skills-standard --skill nestjs-file-uploads --agent claude-codeAre you the author of Nestjs File Uploads?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-nestjs-file-uploads-agent-skills-standard)Do not trust the filename or the client-provided `Content-Type`. Set a Multer size limit and inspect the file's magic bytes with `file-type`/`mmmagic` before accepting it.
```ts
@Post()
@UseInterceptors(FileInterceptor('file', { limits: { fileSize: 5_000_000 } }))
upload(@UploadedFile() file: Express.Multer.File) {
const detected = await fileTypeFromBuffer(file.buffer);
if (!detected || !['image/png', 'image/jpeg', 'application/pdf'].includes(detected.mime)) {
throw new BadRequestException('Unsupported file type');
}
// store using a generated name, not the client filename
}
```
For large files, avoid `MemoryStorage`; stream to object storage or issue a signed URL and validate the object after upload.
Files in this skill
- eval-1.baseline.md
- eval-1.with-skill.md
- eval-2.baseline.md
- eval-2.with-skill.md
- eval-3.baseline.md
- eval-3.with-skill.md
- trigger-1.md
- trigger-2.md
- trigger-3.md
- trigger-4.md
Attribution
Related skills
View all in development →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.