使用Node.js将文件上传到S3

时间:2018-12-22 21:09:05

标签: amazon-s3 multer multer-s3

我正在尝试使用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": "*"
        }
    ]
}

我仍然遇到相同的错误。

0 个答案:

没有答案
相关问题