Skip to content

wendel211/upload-file-server

Repository files navigation

Nest Logo

NestJS Upload & Static File Server

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


Features

  • 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

Project Structure

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

Installation & Setup

Clone the repository

git clone https://github.com/yourusername/nest-upload-server.git
cd nest-upload-server

Install dependencies

npm install

Run the application

npm run start:dev

Application URLs

Resource URL
Main API http://localhost:3000
Swagger Documentation http://localhost:3000/api
Uploaded Files http://localhost:3000/uploads/...

API Endpoints

POST /uploads/{context}

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-data

Upload 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"
}

Technologies Used

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

Environment Variables

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

Future Improvements

  • Authentication and file ownership validation
  • Cloud storage integration (AWS S3 / Firebase Storage)
  • File metadata persistence (TypeORM + PostgreSQL)
  • File deletion and update endpoints

Author

Wendel Muniz
Full Stack Developer & Software Engineering Student

Part of the NestJS Practical Trail — Project 4/10: Upload & File Server

LinkedIn | GitHub


"Build step by step. Learn deeply. Deploy confidently."

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published