A modular NestJS application designed to handle file uploads and serve static files efficiently. This project demonstrates implementation of upload endpoints using Multer, static file serving with ServeStaticModule, file type and size validation, and dynamic upload organization by context.
Upload & File Server
- File upload via Multer middleware
- Static file serving using ServeStaticModule
- File type and size validation
- Dynamic upload organization by context (users, products, documents)
- Public URL generation for uploaded files
- Complete API documentation with Swagger UI
nest-upload-server/
├── uploads/
│ ├── users/
│ │ └── user-1730928431379.png
│ ├── products/
│ └── documents/
├── src/
│ ├── uploads/
│ │ ├── uploads.controller.ts
│ │ ├── uploads.service.ts
│ │ └── uploads.module.ts
│ ├── app.module.ts
│ └── main.ts
├── package.json
├── tsconfig.json
└── .env
git clone https://github.com/yourusername/nest-upload-server.git
cd nest-upload-servernpm installnpm run start:dev| Resource | URL |
|---|---|
| Main API | http://localhost:3000 |
| Swagger Documentation | http://localhost:3000/api |
| Uploaded Files | http://localhost:3000/uploads/... |
Upload a file dynamically into a context-based folder.
Path Parameter:
| Name | Type | Description |
|---|---|---|
| context | string | Folder name (users, products, documents, etc.) |
Request (multipart/form-data):
| Field | Type | Description |
|---|---|---|
| file | binary | The file to upload (image or PDF) |
Example Request:
POST /uploads/users
Content-Type: multipart/form-dataUpload avatar.png with field name file.
Successful Response:
{
"message": "Upload realizado com sucesso!",
"url": "http://localhost:3000/uploads/users/file-1730928431379-321654987.png",
"context": "users",
"originalName": "avatar.png",
"size": 25433,
"mimetype": "image/png"
}| Technology | Description |
|---|---|
| NestJS | Progressive Node.js framework for building scalable applications |
| Multer | Middleware for handling multipart/form-data file uploads |
| ServeStaticModule | Module for serving static assets |
| Swagger | API documentation and testing interface |
| TypeScript | Strongly typed JavaScript for enhanced maintainability |
| Variable | Default | Description |
|---|---|---|
| APP_URL | http://localhost:3000 | Base URL for generating file links |
Create a .env file in your project root:
APP_URL=http://localhost:3000- Authentication and file ownership validation
- Cloud storage integration (AWS S3 / Firebase Storage)
- File metadata persistence (TypeORM + PostgreSQL)
- File deletion and update endpoints
Wendel Muniz
Full Stack Developer & Software Engineering Student
Part of the NestJS Practical Trail — Project 4/10: Upload & File Server
"Build step by step. Learn deeply. Deploy confidently."