nextjs-aws-s3

  • i7_388268
    了解作者
  • 98KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-09 13:10
    上传日期
Next.js + AWS S3上传 这是Next.js应用程序的示例,允许您将照片上传到S3存储桶。 入门 选项1:使用现有的S3存储桶。 检索您现有的访问密钥,秘密密钥,S3存储桶区域和名称。 单击“部署”以自动设置环境变量后,请提供这些值。 选项2:创建一个S3存储桶。 使用AWSCloudFormationFullAccess和AmazonS3FullAccess权限创建一个新的。 保存访问密钥和秘密密钥。 安装并运行aws configure 。 这将提示您输入访问密钥和秘密密钥。 创建一个类似于.env.example的.env.local文件。 运行cdk deploy以使用正确的CORS设置创建S3存储桶。 访问您新创建的S3存储桶并检索名称和区域。 将名称和区域添加到.env.local 。 运行yarn dev在localhost:3000处启动N
nextjs-aws-s3-master.zip
  • nextjs-aws-s3-master
  • bin
  • hello-cdk.js
    189B
  • package.json
    453B
  • package-lock.json
    360.5KB
  • .env.example
    53B
  • .npmignore
    51B
  • pages
  • index.js
    839B
  • api
  • upload-url.js
    620B
  • cdk.json
    201B
  • .gitignore
    60B
  • lib
  • hello-cdk-stack.js
    559B
  • README.md
    1.9KB
内容介绍
# Next.js + AWS S3 Upload This is an example of a Next.js application allowing you to upload photos to an S3 bucket. ## Getting Started **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. [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https%3A%2F%2Fgithub.com%2Fleerob%2Fnextjs-aws-s3&env=ACCESS_KEY,SECRET_KEY,REGION,BUCKET_NAME&envDescription=AWS%20S3%20bucket%20information%20and%20keys.) **Option 2: Create an S3 bucket.** 1. Create a new [IAM role](https://aws.amazon.com/iam/) with permission for `AWSCloudFormationFullAccess` and `AmazonS3FullAccess`. 1. Save the access key and secret key. 1. Install the [AWS CLI](https://aws.amazon.com/cli/) and run `aws configure`. 1. This will prompt you to enter the access key and secret key. 1. Create an `.env.local` file similar to `.env.example`. 1. Run `cdk deploy` to create an S3 bucket with the correct CORS settings. 1. Visit your newly created S3 bucket and retrieve the name and region. 1. Add the name and region to `.env.local`. 1. Run `yarn dev` to start the Next app at `localhost:3000`. 1. Choose a `.png` or `.jpg` file. 1. You should see your file successfully uploaded to S3. This example uses [`createPresignedPost`](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#createPresignedPost-property) instead of [`getSignedUrlPromise`](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#getSignedUrlPromise-property) to allow setting max/min file sizes with `content-length-range`. ## Commands - `yarn dev` – Starts the Next.js app at `localhost:3000`. - `cdk deploy` – Deploy this stack to your default AWS account/region - `cdk diff` – Compare deployed stack with current state - `cdk synth` – Emits the synthesized CloudFormation template
评论
    相关推荐