This is an example of a Next.js application allowing you to upload photos to an S3 bucket.
Option 1: Use an existing S3 bucket.
Retrieve your existing access key, secret key, S3 bucket region and name. Provide those values after clicking "Deploy" to automatically set the environment variables.
Option 2: Create an S3 bucket.
AmazonS3FullAccess.aws configure..env.local file similar to .env.example.cdk bootstrap.cdk deploy to create an S3 bucket with an IAM policy..env.local.yarn dev to start the Next.js app at localhost:3000..png or .jpg file.This example uses createPresignedPost instead of getSignedUrlPromise to allow setting max/min file sizes with content-length-range.
yarn dev – Starts the Next.js app at localhost:3000.cdk deploy – Deploy this stack to your default AWS account/regioncdk diff – Compare deployed stack with current statecdk synth – Emits the synthesized CloudFormation templateExecute create-next-app with npm or Yarn to bootstrap the example:
npx create-next-app --example https://github.com/vercel/examples/tree/main/solutions/aws-s3-image-upload aws-s3-image-upload # or yarn create next-app --example https://github.com/vercel/examples/tree/main/solutions/aws-s3-image-upload aws-s3-image-upload
Copy the .env.example file in this directory to .env.local and set your AWS settings
cp .env.example .env.local
Next, run Next.js in development mode:
npm install npm run dev # or yarn yarn dev
Deploy it to the cloud with Vercel (Documentation).
Use AWS S3 to upload images to a bucket from a Next.js application.
This is an example of a Next.js application allowing you to upload photos to an S3 bucket.
Option 1: Use an existing S3 bucket.
Retrieve your existing access key, secret key, S3 bucket region and name. Provide those values after clicking "Deploy" to automatically set the environment variables.
Option 2: Create an S3 bucket.
AmazonS3FullAccess.aws configure..env.local file similar to .env.example.cdk bootstrap.cdk deploy to create an S3 bucket with an IAM policy..env.local.yarn dev to start the Next.js app at localhost:3000..png or .jpg file.This example uses createPresignedPost instead of getSignedUrlPromise to allow setting max/min file sizes with content-length-range.
yarn dev – Starts the Next.js app at localhost:3000.cdk deploy – Deploy this stack to your default AWS account/regioncdk diff – Compare deployed stack with current statecdk synth – Emits the synthesized CloudFormation templateExecute create-next-app with npm or Yarn to bootstrap the example:
npx create-next-app --example https://github.com/vercel/examples/tree/main/solutions/aws-s3-image-upload aws-s3-image-upload # or yarn create next-app --example https://github.com/vercel/examples/tree/main/solutions/aws-s3-image-upload aws-s3-image-upload
Copy the .env.example file in this directory to .env.local and set your AWS settings
cp .env.example .env.local
Next, run Next.js in development mode:
npm install npm run dev # or yarn yarn dev
Deploy it to the cloud with Vercel (Documentation).