Getting 403 (Forbidden) when uploading to S3 with a signed URL

后端 未结 6 1352
礼貌的吻别
礼貌的吻别 2021-02-07 03:30

I\'m trying to generate a pre-signed URL then upload a file to S3 through a browser. My server-side code looks like this, and it generates the URL:

let s3 = new          


        
6条回答
  •  执念已碎
    2021-02-07 03:59

    This code was working with credentials and a bucket I created several years ago, but caused a 403 error on recently created credentials/buckets:

    const s3 = new AWS.S3({
      region: region,
      accessKeyId: process.env.AWS_ACCESS_KEY,
      secretAccessKey: process.env.AWS_SECRET_KEY,
    })
    

    The fix was simply to add signatureVersion: 'v4'.

    const s3 = new AWS.S3({
      signatureVersion: 'v4',
      region: region,
      accessKeyId: process.env.AWS_ACCESS_KEY,
      secretAccessKey: process.env.AWS_SECRET_KEY,
    })
    

    Why? I don't know.

提交回复
热议问题