【发布时间】:2021-02-07 22:41:35
【问题描述】:
我正在尝试在将图像上传到 Amazon S3 之前调整其大小。我找到了有关如何实现这一点的文档,但我怀疑我的实现不正确。我包括下面的代码。我做错了什么?
const multerFilter = (req, file, cb) => {
if (file.mimetype.startsWith('image')) {
cb(null, true);
} else {
cb(new AppError('Not an image! Please upload images only.', 400), false);
}
};
const upload = multer({
storage: multerS3({
s3: s3,
acl: 'public-read',
bucket: 'BUCKETNAME',
contentType: multerS3.AUTO_CONTENT_TYPE,
}),
fileFilter: multerFilter,
shouldTransform: function (req, file, cb) {
cb(null, /^image/i.test(file.mimetype));
},
transforms: [
{
id: 'original',
key: function (req, file, cb) {
cb(null, 'image-original.jpg');
},
transform: function (req, file, cb) {
cb(null, sharp().resize(100, 100).jpg());
},
},
],
});
【问题讨论】:
标签: node.js amazon-s3 multer multer-s3