Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
Use AWS S3 to upload images to a bucket from a Next.js application.
AWS S3 Image Upload is a Next.js example application from Vercel's examples repository that demonstrates a browser-to-S3 image upload flow using the AWS SDK's presigned POST URLs.
This is an official example from Vercel's examples repository, built with Next.js. It takes a locally selected .png or .jpg file and uploads it directly to an S3 bucket through a presigned POST URL, so the image never goes through your application server. The project runs on Next.js and can be deployed to Vercel with a single click, or bootstrapped locally with create-next-app and pnpm.
createPresignedPost method instead of getSignedUrlPromise so you can set minimum and maximum file sizes via content-length-range.AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION, and AWS_BUCKET_NAME; the AWS SDK picks them up automatically.s3:DeleteObject, s3:GetObject, s3:ListBucket, s3:PutObject, and s3:PutObjectAcl.pnpm dev or npm run dev at localhost:3000.content-length-range and the IAM policy restrict what can be uploaded and by whom.After deploying or running locally, you create an S3 bucket (with ACLs enabled and public-access-block adjusted) and an IAM user with the listed permissions. You then set the environment variables, configure CORS on the bucket with the included JSON, and start the app. The upload page accepts a .png or .jpg, generates a presigned POST URL via the AWS SDK, and uploads the file directly to S3.
Yes. This is an open-source example in the Vercel examples repository, so you can use and modify it freely. You only pay AWS for the S3 storage and requests you use.
You need an S3 bucket and an IAM user with access keys. The example depends on the AWS SDK's client-s3 package and does not require Lambda or API Gateway.
Yes. The example runs locally with pnpm dev and relies only on standard environment variables, so it can be hosted on any platform that supports Next.js.
The example uses a presigned POST policy with content-length-range to cap file sizes, and the IAM policy restricts which actions the access key can perform.