Back to Templates

Tencent COS Batch Uploader

An Tencent COS batch upload template based on Next.js 14 and App Router, demonstrating how to perform pre-signed uploads using Tencent COS; As well as bucket file management, bucket lifecycle management, bucket permission management, etc.

View Demo
FrameworkNext.js
DatabaseTencent COS
An Tencent COS batch upload template based on Next.js 14 and App Router, demonstrating how to perform pre-signed uploads using Tencent COS; As well as bucket file management, bucket lifecycle management, bucket permission management, etc.

๐Ÿš€ Tencent Cloud COS Batch Uploader

A fully-featured, beautifully designed Tencent Cloud COS batch file upload system with drag-and-drop upload, progress monitoring, and advanced features.

โœจ Features

๐Ÿ“ File Upload

  • โœ… Drag & Drop - Support dragging files to the page for upload
  • โœ… Click to Select - Traditional file selection method
  • โœ… Batch Processing - Select multiple files for batch upload at once
  • โœ… File Preview - Display image thumbnails and video covers
  • โœ… File Information - Show file format, size and other details

๐Ÿ“Š Progress Monitoring

  • โœ… Real-time Progress Bar - Display upload progress for each file
  • โœ… Upload Status - Pending, uploading, success, and failure status indicators
  • โœ… Progress Overlay - Show semi-transparent progress layer on file preview during upload
  • โœ… Error Handling - Display error messages and retry options when upload fails

โš™๏ธ Advanced Configuration

  • โœ… Concurrency Control - Configurable number of simultaneous uploads
  • โœ… File Selection - Check/uncheck files to upload

๐Ÿ“‹ Bucket Management

  • โœ… Bucket View - View list of uploaded files
  • โœ… File Details - Click to view detailed file information

๐ŸŽจ User Interface

  • โœ… Modern Design - Clean and beautiful user interface
  • โœ… Responsive Layout - Adapt to different screen sizes
  • โœ… Status Feedback - Rich visual feedback and interactive effects

๐Ÿš€ Quick Start

1. Configure Tencent Cloud COS

Please configure your Tencent Cloud COS settings before use:

# Copy environment variable template
cp .env.example .env.local

# Edit configuration file
nano .env.local

Fill in your Tencent Cloud COS configuration:

COS_SECRET_ID=your-secret-id
COS_SECRET_KEY=your-secret-key
COS_BUCKET=your-bucket-name-appid
COS_REGION=your-bucket-region

2. Tencent Cloud COS Setup

Create COS Bucket

  1. Log in to Tencent Cloud Console
  2. Create a new COS bucket
  3. Configure CORS policy:
[
  {
    "allowedOrigin": ["*"],
    "allowedMethod": ["GET", "PUT", "POST", "DELETE", "HEAD"],
    "allowedHeader": ["*"],
    "exposeHeader": ["ETag", "Content-Length"],
    "maxAgeSeconds": 3600
  }
]

Create Access Keys

  1. Go to Access Management > API Key Management
  2. Create a new key pair (SecretId and SecretKey)
  3. Configure bucket access permission policy:
{
  "version": "2.0",
  "statement": [
    {
      "effect": "allow",
      "action": [
        "name/cos:GetObject",
        "name/cos:PutObject",
        "name/cos:DeleteObject",
        "name/cos:GetBucket"
      ],
      "resource": [
        "qcs::cos:ap-guangzhou:uid/your-appid:your-bucket-name-appid/*"
      ]
    }
  ]
}

๐Ÿ”ง Development

Install Node.js 18.x

The project is developed using Next.js 14.x, so the minimum supported version of Node.js is 18.x

Install Dependencies

npm install

Start Development Server

npm run dev
# Or use startup script
./start.sh

Build for Production

npm run build
npm start

Project currently running at: http://localhost:3004

Code Linting

npm run lint

๐Ÿ“– User Guide

Upload Files

  1. Visit http://localhost:3004
  2. Select "Upload" page (default)
  3. Drag files to upload area or click to select files
  4. Configure upload options
  5. Check the files to upload
  6. Click "Start Upload"

View Bucket

  1. Click "Bucket" menu on the left
  2. Browse uploaded files
  3. Click on a file to view detailed information

Advanced Features

  • Batch Operations: Upload multiple files simultaneously

๐Ÿ› ๏ธ Technical Architecture

Frontend Stack

  • Next.js 14 - React full-stack framework
  • TypeScript - Type safety
  • Tailwind CSS - Styling framework
  • Lucide React - Icon library

Backend Integration

  • Tencent Cloud COS JS SDK - COS client
  • Presigned URLs - Secure file upload

Core Features

  • Custom Hooks - File upload logic encapsulation
  • State Management - React useState/useEffect
  • Error Handling - Comprehensive exception handling mechanism

๐Ÿ“ Project Structure

cos-batch-uploader/
โ”œโ”€โ”€ app/                    # Next.js App Router
โ”‚   โ”œโ”€โ”€ api/               # API routes
โ”‚   โ”‚   โ”œโ”€โ”€ upload-batch/  # Batch upload API
โ”‚   โ”‚   โ”œโ”€โ”€ cos-files/     # COS file management API
โ”‚   โ”‚   โ””โ”€โ”€ storage-usage/ # Storage usage API
โ”‚   โ”œโ”€โ”€ components/        # React components
โ”‚   โ”‚   โ”œโ”€โ”€ FileUpload/    # File upload components
โ”‚   โ”‚   โ”œโ”€โ”€ Navigation/    # Navigation components
โ”‚   โ”‚   โ””โ”€โ”€ ui/           # Common UI components
โ”‚   โ”œโ”€โ”€ hooks/            # Custom Hooks
โ”‚   โ”‚   โ”œโ”€โ”€ useFileUpload.ts
โ”‚   โ”‚   โ””โ”€โ”€ useCOSFiles.ts
โ”‚   โ”œโ”€โ”€ lib/              # Utility library
โ”‚   โ”‚   โ””โ”€โ”€ cos-client.ts  # COS client configuration
โ”‚   โ”œโ”€โ”€ types/            # TypeScript type definitions
โ”‚   โ”œโ”€โ”€ upload/           # Upload page
โ”‚   โ”œโ”€โ”€ history/          # History page
โ”‚   โ””โ”€โ”€ globals.css       # Global styles
โ”œโ”€โ”€ public/               # Static assets
โ”œโ”€โ”€ .env.example          # Environment variable template
โ”œโ”€โ”€ .env.local           # Local environment variables (needs configuration)
โ”œโ”€โ”€ package.json         # Project dependencies
โ”œโ”€โ”€ tailwind.config.js   # Tailwind configuration
โ”œโ”€โ”€ start.sh            # Startup script
โ””โ”€โ”€ README.md           # Project documentation

๐Ÿ“š Reference Documentation