如何解决如何在上传时使用multer压缩图像大小?
如何在上传时压缩图像大小,我的S3存储桶中将有很多文件,所以我需要它。
我该如何转换此代码呢?
app.post('/api/v1/upload',upload.array('image',1),(req,res) => {
res.send({ image: req.file });
});
aws.config.update({
secretAccessKey: process.env.SECRET_ACCESS_KEY,accessKeyId: process.env.ACCESS_KEY_ID,region: 'us-east-1' //E.g us-east-1
});
const s3 = new aws.S3();
const fileFilter = (req,file,cb) => {
if (file.mimetype === 'image/jpeg' || file.mimetype === 'image/png') {
cb(null,true);
} else {
cb(new Error('Invalid file type,only JPEG and PNG is allowed!'),false);
}
};
const upload = multer({
fileFilter: fileFilter,storage: multerS3({
acl: 'public-read',s3,bucket: 'oldst123',key: function(req,cb) {
req.file = file.originalname;
cb(null,file.originalname);
}
})
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。