S3 File Uploads in Next.js: The Right Way
AWSS3cloud storage

S3 File Uploads in Next.js: The Right Way

Jed Llenado15 Jan 2025

Handling file uploads properly in Next.js requires a presigned URL flow — you never want to route files through your server.

The Flow

Client requests a presigned URL from your API → API generates it using AWS SDK with time-limited permissions → Client uploads directly to S3 → Client confirms upload to your API → API stores the S3 URL in your DB.

Security

Always validate file type and size server-side before generating the presigned URL. Use a random UUID for the S3 key to prevent enumeration.

All Postsjedllenado.online