File uploading with Express 4.0: req.files undefined

后端 未结 9 1860
感动是毒
感动是毒 2020-11-22 10:10

I\'m attempting to get a simple file upload mechanism working with Express 4.0 but I keep getting undefined for req.files in the app.post

9条回答
  •  误落风尘
    2020-11-22 10:57

    PROBLEM SOLVED !!!!!!!

    Turns out the storage function DID NOT run even once. because i had to include app.use(upload) as upload = multer({storage}).single('file');

     let storage = multer.diskStorage({
            destination: function (req, file, cb) {
                cb(null, './storage')
              },
              filename: function (req, file, cb) {
                console.log(file) // this didn't print anything out so i assumed it was never excuted
                cb(null, file.fieldname + '-' + Date.now())
              }
        });
    
        const upload = multer({storage}).single('file');
    

提交回复
热议问题