
AWSS3cloud storage
S3 File Uploads in Next.js: The Right Way
Jed Llenado15 Jan 20251 min read
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.
Enjoyed this? Get new posts by email
One short email when I publish something new. No spam, and you can reply to unsubscribe.

All Postsjedllenado.com