我正在尝试使用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": "*"
}
]
}
我仍然遇到相同的错误。