File Uploads for AI Coders
Let users upload images, documents, and videos. Learn the UI patterns, storage options, and validation rules to get it right.
In this chapter
- Where uploaded files actually live (and where they shouldn't)
- How to add drag-and-drop uploads with a simple AI prompt
- How to limit file size and types so users don't break your app
- Cloud storage options like Uploadthing, Supabase, and R2
Upload UI Patterns
Drag & drop files here
or click to browse
PNG, JPG, WebP up to 5MB
Accepted formats: JPG, PNG. Max 5MB.
vacation-photo.jpg
2.4 MB · 1920 × 1080
8.1 MB · Complete
3.2 of 4.8 MB · Uploading...
1.5 MB · Waiting...
File Types to Know
- WebP: Best for web, small file size, great quality
- PNG: Supports transparency, larger files
- JPG/JPEG: Good for photos, no transparency
- SVG: Vector graphics, scales infinitely
- PDF: Universal document format
- CSV: Spreadsheet data, easy to parse
- DOCX: Microsoft Word documents
- TXT: Plain text, simplest format
- MP4: Most common video format
- WebM: Modern video, smaller size
- MP3: Audio files, widely supported
- GIF: Animated images, large files
Storage Services Compared
- No egress (download) fees: huge cost savings
- Global CDN built in
- S3-compatible API (easy to switch)
- Newer service, smaller community
- Dashboard UI is more basic
- Battle-tested, used by millions of apps
- Massive ecosystem of tools and integrations
- Fine-grained access controls
- Egress fees add up fast
- Complex pricing and configuration
- Integrated with Supabase Auth and database
- Simple API with row-level security
- Generous free tier (1GB)
- Tied to the Supabase ecosystem
- Fewer advanced features than S3
- Easiest setup for Next.js projects
- Built-in file validation and type safety
- Pre-built React upload components
- Only works with Next.js/React
- Less control over storage infrastructure
Validation Checklist
AI Prompts for File Uploads
Copy-paste these prompts to quickly add file upload features to your project.
“Add an image upload with drag and drop, preview, and 5MB limit. Accept only JPG, PNG, and WebP. Show an error message if the file is too large or wrong type.”
“Add a profile photo upload that shows a circular preview of the selected image. Include a 'Remove' button. Resize the image to 400x400 on the server before saving.”
“Add a multi-file upload for a photo gallery. Let users drag up to 10 images at once. Show thumbnails with individual progress bars and remove buttons for each file.”
“Set up Uploadthing for file uploads in my Next.js app. Create an upload endpoint that accepts images up to 4MB and PDFs up to 16MB. Show upload progress in the UI.”
“Add a document upload form that accepts PDFs and CSV files. Show the file name and size after selection. Upload to Supabase Storage and save the URL in the database.”
Frequently Asked Questions
Where should I store uploaded files?
Use a cloud storage service like Uploadthing, Supabase Storage, or Cloudflare R2. Never store uploads in your project's file system: deployed servers have limited disk space and files get wiped on redeployment.
How do I limit file sizes?
Set a maximum file size on both the frontend (to warn users before uploading) and the backend (to enforce the limit). Common limits: 5MB for images, 10MB for documents, 50MB for videos. Tell your AI tool the limits and it will add validation.
How do I show upload progress?
Most upload libraries (like Uploadthing or the Fetch API with XMLHttpRequest) provide progress events. Tell your AI tool to add a progress bar that shows the upload percentage. This is important for large files so users know the upload is working.