Express-Fileupload无法解析heroku中的文件

时间:2018-10-29 21:02:53

标签: javascript express heroku file-upload body-parser

我正在使用express-fileupload解析请求的主体并访问随请求发送的所有文件。当我尝试在本地执行此操作时效果很好,但是当我将其推送到heroku时,文件没有被解析-而是req.filesnull。我的代码如下:

解析中间件:

var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
const fileUpload = require('express-fileupload');

module.exports = function (app) {
    app.use(cookieParser());
    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({ extended: true }));
    app.use(fileUpload());  // EXPRESS-FILEUPLOAD BEING USED HERE
};

路由文件:

router.post('/photo', function(req, res, next) {
    console.log("INSIDE OF THE ROUTE =======>>>>>");
    const userId = req.body.userId;
    const busketName = 'my-bucket-name';
    let newPhotosArray = [];
    var busboy = new Busboy({ headers: req.headers });
    req.pipe(busboy);

    busboy.on('finish', function() {
        const filesObj = req.files;
        console.log('FILES OBJ: ', filesObj);  // THIS IS LOGGED OUT AS NULL ON HEROKU - LOCALLY IT IS AN OBJECT WITH FILES

        // rest of code....
    });
});

当我在本地使用该代码时,它的效果很好。但是,当我将代码推送到Heroku时,req.files为null。为什么会这样?

0 个答案:

没有答案