任何人都知道如何为 multer-imager dirname 字段设置自定义文件夹名称? https://www.npmjs.com/package/multer-imager
const imager = require('multer-imager');
var S3ReziseStorage = imager({
bucket: process.env.AWS_BUCKET_NAME,
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
region: 'us-east-1',
filename: function (req, file, cb) {
var folder = req.body.category ? req.body.category.toLowerCase() : '';
var dir = 'uploads/'+ folder;
cb(null, Date.now()+'-'+file.originalname)
},
dirname: dir
})
var upload = multer({ storage: S3ReziseStorage });
正如您从上面看到的,我正在尝试从 req 中提取文件夹名称,然后将其传递给 dirname。但是现在变量在文件名方法的范围内,似乎没有另一种方法来设置自定义目录名。