我想在用户上传照片前,对其 token 进行验证处理,可是使用 multer 中间件后,发现无法在中间件之前获取 text 类型的数据,只有在 multer 处理完图片后才能解析到,该如何处理呢???
迷茫2017-04-17 11:55:07
I also discovered this problem. Multer was uploaded directly. It has a separate event, but it seems to be difficult to use.
This is what I wrote
coffeescript
body = req.body path = res.locals.Path f = req.files.uploadpic if not f? or f is "" return res.send new helper.recode(201,"请指定上传的图片") console.log oldname console.log body,path console.log req.files console.log f location = __dirname+"/../../public/uploadDir" oldname = location+"/"+f.name if not body.album? or body.album is "" fs.unlink oldname, (err)-> res.send new helper.recode(201,"相册 ID 不能为空") return false if not body.token? or body.token is "" fs.unlink oldname, (err)-> res.send new helper.recode(201,"您还没有登录,请先登录") return false if not res._user? or res._user is "" fs.unlink oldname, (err)-> res.send new helper.recode(201,"您还没有登录,请先登录") return false
If the token is incorrect, delete the obtained image or file.
If the token check is OK, just rename the uploaded file.