我可以在多个自定义存储引擎 _handleFile 函数中访问 res 对象吗
can i acess res object in multer custom storage engine _handleFile function
我需要在多个自定义存储引擎_handleFile函数中访问res对象,有什么办法吗?目前只有 req, file, cb
MyCustomStorage.prototype._handleFile = function _handleFile (req, file, cb) {
this.getDestination(req, file, function (err, path) {
if (err) return cb(err)
var outStream = fs.createWriteStream(path)
file.stream.pipe(outStream)
outStream.on('error', cb)
outStream.on('finish', function () {
cb(null, {
path: path,
size: outStream.bytesWritten
})
})
})
}
没有 res 对象可以访问
res
对象在 req.res
下可用。你可以自己测试一下:
app.use((req, res, next) => {
console.log(req.res === res); // true
next();
})
我没有找到任何文档,但您可以查看来源 here。
我需要在多个自定义存储引擎_handleFile函数中访问res对象,有什么办法吗?目前只有 req, file, cb
MyCustomStorage.prototype._handleFile = function _handleFile (req, file, cb) {
this.getDestination(req, file, function (err, path) {
if (err) return cb(err)
var outStream = fs.createWriteStream(path)
file.stream.pipe(outStream)
outStream.on('error', cb)
outStream.on('finish', function () {
cb(null, {
path: path,
size: outStream.bytesWritten
})
})
})
}
没有 res 对象可以访问
res
对象在 req.res
下可用。你可以自己测试一下:
app.use((req, res, next) => {
console.log(req.res === res); // true
next();
})
我没有找到任何文档,但您可以查看来源 here。