Skip to content

Parthmudgal15105/FileUploadReal

Repository files navigation

File Upload Application

A modern, distributed file uploader with chunked uploads, integrity verification, and beautiful UI.

✨ Features

  • Chunked File Upload: Large files split into chunks for reliable upload
  • Beautiful UI: Modern glassmorphism design with smooth animations
  • File Type Icons: Visual indicators for different file types
  • Real-time Progress: Live upload speed, ETA, and progress tracking
  • Toast Notifications: User-friendly notifications for all actions
  • Upload Resume/Retry: Resume failed or incomplete uploads
  • File Management: View, download, and delete uploads
  • Dark Mode: Full dark mode support
  • Security: Rate limiting, file validation, integrity checks

πŸš€ Quick Start

Prerequisites

  • Node.js >= 18.x
  • npm or yarn
  • PostgreSQL >= 12.x

PostgreSQL Setup

  1. Install PostgreSQL (if not already installed)

    • Windows: Download from postgresql.org
    • Mac: brew install postgresql@14
    • Linux: sudo apt-get install postgresql postgresql-contrib
  2. Create Database

    # Connect to PostgreSQL
    psql -U postgres
    
    # Create database
    CREATE DATABASE fileupload;
    
    # Exit
    \q
  3. Configure Backend Environment

    cd backend
    cp .env.example .env
    # Edit .env with your PostgreSQL credentials

Install Dependencies

# Install all dependencies (root, backend, and frontend)
npm run install:all

# Or manually:
npm install
cd backend && npm install
cd ../frontend && npm install

Development Mode

# Run both frontend and backend concurrently
npm run dev

# Or run separately:
npm run dev:backend   # Backend on http://localhost:4000
npm run dev:frontend  # Frontend on http://localhost:5173

Production Build

npm run build        # Builds both backend and frontend
npm run start:backend   # Start production backend
npm run start:frontend  # Preview production frontend

πŸ“ Project Structure

file-upload-app/
β”œβ”€β”€ backend/              # Express backend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ index.ts              # Server entry point
β”‚   β”‚   β”œβ”€β”€ config/
β”‚   β”‚   β”‚   └── constants.ts      # Configuration
β”‚   β”‚   β”œβ”€β”€ controllers/
β”‚   β”‚   β”‚   β”œβ”€β”€ file.controller.ts
β”‚   β”‚   β”‚   └── upload.controller.ts
β”‚   β”‚   β”œβ”€β”€ database/
β”‚   β”‚   β”‚   β”œβ”€β”€ db.ts             # Database setup
β”‚   β”‚   β”‚   └── models.ts         # TypeScript types
β”‚   β”‚   β”œβ”€β”€ middleware/
β”‚   β”‚   β”‚   └── rateLimit.ts      # Rate limiting
β”‚   β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”‚   β”œβ”€β”€ file.routes.ts
β”‚   β”‚   β”‚   └── upload.routes.ts
β”‚   β”‚   └── utils/
β”‚   β”‚       β”œβ”€β”€ fileUtils.ts      # File operations
β”‚   β”‚       └── hashUtils.ts      # Hash calculations
β”‚   β”œβ”€β”€ chunks/           # Temporary chunk storage
β”‚   β”œβ”€β”€ uploads/          # Completed files
β”‚   └── .env              # PostgreSQL configuration
β”‚
└── frontend/             # React frontend
    β”œβ”€β”€ src/
    β”‚   β”œβ”€β”€ components/
    β”‚   β”‚   β”œβ”€β”€ FileUploader.tsx  # Upload component
    β”‚   β”‚   β”œβ”€β”€ UploadsList.tsx   # History component
    β”‚   β”‚   └── ui/               # UI components
    β”‚   β”œβ”€β”€ contexts/
    β”‚   β”‚   └── ThemeContext.tsx  # Dark mode
    β”‚   β”œβ”€β”€ lib/
    β”‚   β”‚   └── fileIcons.ts      # File type icons
    β”‚   └── config.ts     # Frontend config
    └── dist/             # Production build

πŸ”Œ API Endpoints

Upload Operations

  • POST /api/upload/init - Initialize upload session
  • POST /api/upload/chunk - Upload individual chunk
  • GET /api/upload/status/:uploadId - Get upload status
  • POST /api/upload/resume - Resume failed upload
  • GET /api/upload/resume/:uploadId - Get missing chunks

File Management

  • GET /api/uploads - List all uploads
  • GET /api/download/:uploadId - Download file
  • DELETE /api/upload/:uploadId - Delete upload

βš™οΈ Configuration

Frontend (.env)

VITE_API_BASE_URL=http://localhost:4000/api
VITE_MAX_FILE_SIZE=10737418240  # 10GB
VITE_CHUNK_SIZE=5242880         # 5MB

Backend (.env)

DB_HOST=localhost
DB_PORT=5432
DB_NAME=fileupload
DB_USER=postgres
DB_PASSWORD=postgres

Backend (backend/src/config/constants.ts)

PORT: 4000
MAX_FILE_SIZE: 10GB
MAX_CHUNK_SIZE: 10MB
RATE_LIMIT_MAX_UPLOADS: 50 per 15 minutes

πŸ”’ Security Features

  1. Rate Limiting: 50 uploads per 15 min per IP
  2. File Validation: Whitelist of allowed file types
  3. Size Limits: Configurable max file/chunk sizes
  4. Filename Sanitization: Prevents path traversal
  5. Integrity Verification: SHA-256 hash checks
  6. CORS Protection: Configurable origins

🎨 Supported File Types

  • Documents: PDF, DOC, DOCX, TXT, XLS, XLSX, PPT, PPTX
  • Images: JPG, PNG, GIF, BMP, SVG, WEBP
  • Videos: MP4, AVI, MKV, MOV, WMV, WEBM
  • Audio: MP3, WAV, FLAC, AAC, OGG
  • Archives: ZIP, RAR, 7Z, TAR, GZ
  • Code: JS, TS, PY, JAVA, JSON, XML, CSV

πŸ› οΈ Tech Stack

Frontend

  • React 19 + TypeScript
  • Vite (build tool)
  • Tailwind CSS (styling)
  • Axios (HTTP client)
  • Lucide React (icons)

Backend

  • Node.js + Express
  • TypeScript
  • PostgreSQL (database)
  • Multer (file upload)
  • fs-extra (file operations)

πŸ“ Development Scripts

# Root commands
npm run dev              # Run both frontend & backend
npm run build            # Build both
npm run install:all      # Install all dependencies

# Backend only
npm run dev:backend      # Start dev server
npm run build:backend    # Build TypeScript
npm run start:backend    # Run production

# Frontend only
npm run dev:frontend     # Start dev server
npm run build:frontend   # Build for production
npm run start:frontend   # Preview production build

πŸš€ Next Steps

  • Add user authentication
  • Integrate cloud storage (AWS S3)
  • Add WebSocket for real-time updates
  • Implement file encryption
  • Add compression before upload
  • Create admin dashboard
  • Add unit & integration tests

πŸ“„ License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors