📁

File Upload System

Secure file upload from user to cloud storage — profile photos, documents, product images, and more.

🔄 File Upload Flow

👤UserSelect file🌐FrontendValidate file⚙️API ServerAuth check🔐SanitizeVirus scan☁️StorageS3/GCS/CDN🗄️DatabaseSave URL/meta✅ File stored securely → CDN URL returned to frontend

📋 Upload Flow Step by Step

1
👆User
Click upload → Select file via file picker or drag & drop
2
🌐Frontend
Validate: file type (MIME type), file size limit, dimensions (for images)
3
📤Frontend
Show upload progress bar → Send file via multipart/form-data to API
4
⚙️API Server
Authenticate user (JWT) → Check permission to upload
5
🔐API Server
Sanitize filename → Remove dangerous characters → Generate unique name (UUID)
6
🦠API Server
Virus scan with ClamAV / third-party service (optional but recommended)
7
☁️Storage
Upload to S3 / Google Cloud Storage / Cloudinary with proper ACL (public/private)
8
🔗Storage
Generate CDN URL or signed URL (for private files with expiry)
9
🗄️Database
Save file record: filename, original_name, size, mime_type, url, uploader_id
10
Frontend
Receive file URL → Show preview → Link to record (avatar, document, product image)

☁️ Storage Options

🟠

Amazon S3

Industry standard. Unlimited storage, 99.999999999% durability. Use with CloudFront CDN.

✅ Best for: Enterprise, high traffic
🔵

Google Cloud Storage

Excellent with Firebase projects. Integrated with Google services, strong ML capabilities.

✅ Best for: Firebase apps, GCP projects
🟣

Cloudinary

Specialized for images/videos. Auto-resize, compress, format convert, AI cropping.

✅ Best for: Media-heavy apps, e-commerce
🟢

Supabase Storage

Open-source alternative to Firebase. Built-in RLS policies, PostgreSQL integration.

✅ Best for: Startups, open-source projects
🖥️

Local Server

Simple for small projects, but no redundancy. Use Nginx to serve files.

✅ Best for: Small internal systems, MVP
🐰

Bunny CDN

Affordable CDN with storage. Good performance in Asia. Cost-effective for Thai projects.

✅ Best for: Thai startups, cost-sensitive

🛡️ Upload Security Best Practices

🔍
Validate MIME Type

Don't trust file extension. Check actual MIME type using file-type library.

📝
Rename Files

Generate UUID filename. Never use original filename to prevent path traversal attacks.

🔑
Signed URLs

For private files, generate time-limited signed URLs instead of public access.

📏
Size Limits

Set server-side size limits. Prevent DoS attacks from huge file uploads.

📁
Store Outside Web Root

Never store uploads in public web directory. Serve through your API with auth.

🦠
Virus Scanning

Integrate ClamAV or VirusTotal API to scan uploaded files before storage.

Need a secure file upload system? 📁

We build file management systems with cloud storage, CDN, and security best practices.

← Back to LearnContact Us