File uploading with Express 4.0: req.files undefined

后端 未结 9 1898
感动是毒
感动是毒 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:58

    Here is what i found googling around:

    var fileupload = require("express-fileupload");
    app.use(fileupload());
    

    Which is pretty simple mechanism for uploads

    app.post("/upload", function(req, res)
    {
        var file;
    
        if(!req.files)
        {
            res.send("File was not found");
            return;
        }
    
        file = req.files.FormFieldName;  // here is the field name of the form
    
        res.send("File Uploaded");
    
    
    });
    

提交回复
热议问题