node.js - node express 如何在使用 multer 前对 form-data 格式的 text 数据解析?
黄舟
黄舟 2017-04-17 11:53:07
0
1
695

我想在用户上传照片前,对其 token 进行验证处理,可是使用 multer 中间件后,发现无法在中间件之前获取 text 类型的数据,只有在 multer 处理完图片后才能解析到,该如何处理呢???

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(1)
迷茫

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template