File Uploads for AI Coders | SheCodes
Intermediate 5 min read

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 Zone A dashed-border area where users drag files from their computer. Shows a visual highlight when a file hovers over it. The most intuitive upload experience.

Drag & drop files here

or click to browse

PNG, JPG, WebP up to 5MB

File Input Button A simple 'Choose File' or 'Upload' button that opens the system file picker. Less flashy but works everywhere, including mobile. Always include this as a fallback.
Choose File No file chosen

Accepted formats: JPG, PNG. Max 5MB.

Image Preview After selecting an image, show a thumbnail preview before uploading. Lets users confirm they picked the right file. Add a remove/replace button next to the preview.

vacation-photo.jpg

2.4 MB · 1920 × 1080

Ready Remove
Progress Bar A horizontal bar that fills up as the file uploads. Shows percentage complete. Essential for large files so users know the upload is working and don't close the page.
presentation.pdf100%

8.1 MB · Complete

design-mockup.png67%

3.2 of 4.8 MB · Uploading...

report.docxQueued

1.5 MB · Waiting...

Multi-File Upload Let users select or drag multiple files at once. Show each file in a list with its own preview, progress bar, and remove button. Great for galleries and bulk imports.
Drop more files or browse
beach-sunset.jpg1.8 MB
×
mountain-view.png3.1 MB
×
city-lights.webp2.5 MB
×
forest-trail.jpg4.2 MB
×
4 files · 11.6 MB total Upload All

File Types to Know

Images
  • 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
Documents
  • PDF: Universal document format
  • CSV: Spreadsheet data, easy to parse
  • DOCX: Microsoft Word documents
  • TXT: Plain text, simplest format
Media
  • MP4: Most common video format
  • WebM: Modern video, smaller size
  • MP3: Audio files, widely supported
  • GIF: Animated images, large files

Storage Services Compared

AWS S3 The industry standard for file storage. Extremely reliable and scalable. Every other storage service is basically copying S3's API. Pros
  • Battle-tested, used by millions of apps
  • Massive ecosystem of tools and integrations
  • Fine-grained access controls
Cons
  • Egress fees add up fast
  • Complex pricing and configuration
Best for: Enterprise apps and complex workflows
Supabase Storage File storage built into the Supabase platform. Upload files and manage access with the same auth system you use for your database. Pros
  • Integrated with Supabase Auth and database
  • Simple API with row-level security
  • Generous free tier (1GB)
Cons
  • Tied to the Supabase ecosystem
  • Fewer advanced features than S3
Best for: Projects already using Supabase
Uploadthing A file upload service built specifically for Next.js. Handles the upload flow, validation, and storage so you just write a few lines of code. Pros
  • Easiest setup for Next.js projects
  • Built-in file validation and type safety
  • Pre-built React upload components
Cons
  • Only works with Next.js/React
  • Less control over storage infrastructure
Best for: Next.js apps wanting the fastest setup

Validation Checklist

File Size Limits Always set a maximum file size. For profile photos, 5MB is plenty. For documents, 10-25MB. For videos, 100-500MB. Show a clear error message when a file is too large: 'File must be under 5MB.'
File Type Restrictions Only accept the file types you actually need. For an avatar upload, accept image/jpeg, image/png, image/webp. Reject everything else. This prevents users from accidentally uploading the wrong file.
Image Dimensions For profile photos or banners, check the image dimensions. Minimum 200x200 for avatars, minimum 1200x630 for social share images. Resize on the server if needed.
Server-Side Validation Never trust client-side validation alone. Always re-check file size, type, and content on the server. Someone can bypass your frontend and send anything directly to your API.

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.