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.

About the author

Jed Llenado

Jed is a Filipino software engineer with more than 12 years of experience, based in Saudi Arabia. He builds fast, secure websites and apps, backed by AI automation, digital marketing and UX design.

Request a quote
All Postsjedllenado.com