我正在使用multer上载图像,同时上载了显示错误的图像。我进行了很多搜索,但找不到解决方案。请给我建议一些博客或文档,以便我可以跟着他们了解这些东西
var aws = require("aws-sdk"),
multerS3 = require("multer-s3");
s3 = new aws.S3({
accessKeyId: process.env.ACCESS_KEY_ID,
accessSecretKey: process.env.ACCESS_SECRET_KEY,
region:process.env.REGION,
Bucket: process.env.AWS_BUCKET_NAME,
});
var upload = multer({
storage: multerS3({
s3: s3,
bucket: "******",
metadata: function (req, file, cb) {
cb(null, { fieldName: file.fieldname });
},
key: function (req, file, cb) {
const uniqueSuffix =
"myfile" + Date.now() + "-" + Math.round(Math.random() * 1e9);
cb(null, uniqueSuffix + file.originalname);
},
}),
});
我的存储桶策略
{
"Version": "2012-10-17",
"Id": "Policy****",
"Statement": [
{
"Sid": "*****",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": [
"arn:aws:s3:::******/*",
"arn:aws:s3:::******"
]
}
]
}
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>Authorization</AllowedHeader>
</CORSRule>
</CORSConfiguration>