1

我正在尝试使用 multer-s3 将文件上传到 S3,但出现AccessDenied错误。这里我配置aws服务:

const s3 = new aws.S3({
  secretAccessKey: process.env.AWS_ACCESS_KEY,
  accessKeyId: process.env.AWS_KEY_ID,
  region: process.env.AWS_REGION,
});

const upload = multer({
  storage: multerS3({
    s3,
    bucket: 'my-bucket-name',
    dirname: '/images',
    acl: 'public-read',
    metadata: function (req, file, cb) {
      cb(null, { fieldName: file.fieldname });
    },
    key: function (req, file, cb) {
      cb(null, Date.now().toString());
    },
  }),
});

即使我为我的用户定义了这个策略:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "s3:*",
            "Resource": "*"
        }
    ]
}

我仍然遇到同样的错误。

4

0 回答 0