把文件名里随机数从256位降到128位

This commit is contained in:
陆柯 2021-10-25 09:26:54 +08:00
parent bd64df212f
commit da2968a807

View File

@ -15,7 +15,7 @@ module.exports = {
filename (req, file, cb) {
// 注意req.body 也许还没有信息因为这取决于客户端发送body和file的顺序。必要的信息请从 req.headers 传递,例如 _passtoken在multer时尚未进入路由不存在已装好的 _passtokenSource
const fileNameExtension = path.extname(file.originalname)
const filename = `${Date.now()}_${crypto.randomBytes(32).toString('hex')}${fileNameExtension}`
const filename = `${Date.now()}_${crypto.randomBytes(16).toString('hex')}${fileNameExtension}`
//const _passtokenSource = webtoken.verifyToken(req.headers._passtoken, wo.envi.tokenKey) || {}
//const filename = `${req.path.replace(/^\/api\d*/, '')}_${_passtokenSource.uuid}_${Date.now()}${fileNameExtension}` // 如果最终 filename 含有 / (例如当 req.path 为 Who/todo则必须已经存在该目录否则在这里就出错不会进入下面流程。
cb(null, filename)