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.
| Framework | Next.js |
| Database | Tencent COS |
๐ 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
- Log in to Tencent Cloud Console
- Create a new COS bucket
- Configure CORS policy:
[
{
"allowedOrigin": ["*"],
"allowedMethod": ["GET", "PUT", "POST", "DELETE", "HEAD"],
"allowedHeader": ["*"],
"exposeHeader": ["ETag", "Content-Length"],
"maxAgeSeconds": 3600
}
]
Create Access Keys
- Go to Access Management > API Key Management
- Create a new key pair (SecretId and SecretKey)
- 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
- Visit http://localhost:3004
- Select "Upload" page (default)
- Drag files to upload area or click to select files
- Configure upload options
- Check the files to upload
- Click "Start Upload"
View Bucket
- Click "Bucket" menu on the left
- Browse uploaded files
- 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