首页 > 解决方案 > 在 multer s3 模块中调整图像大小

问题描述

我想调整图像大小并将其上传到 s3 存储桶。

我尝试multer-s3-transform了模块,但它没有用。

我尝试过使用它,但它也没有奏效。

const upload = multer({
  fileFilter: fileFilter,
  storage: multerS3({
    s3: s3,
    bucket: 'bucket',
    acl: 'public-read',
    shouldTransform: function(req, file, cb) {
      cb(null, /^image/i.test(file.mimetype));
    },
    transforms: [
      {
        id: 'original',
        transform: function(req, file, cb) {
          //Perform desired transformations
          cb(
            null,
            sharp()
              .resize(600, 600)
              .max()
          );
        }
      }
    ]
  })
});

标签: node.jsimage-resizingmultermulter-s3

解决方案


推荐阅读