2
votes

I am using express-fileupload to parse the body of my request and access any files that are sent with the request. This works fine when I am trying to do this locally but when I push it to heroku, the files are not being parsed - instead req.files is null. My code is below:

Parsing middleware:

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
};

Routes file:

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....
    });
});

The code works great when I use it locally. However, when I push the code to Heroku, req.files is null. Why is this?

What's the purpose of using busboy here? req.files should be immediately populated with uploaded files without the need for busboy - richardgirges
you're right, that is unnecessary, but that does not address my issue. Do you have any advice on that? - georgej
I'll need more information. What version of node are you using locally? What version of node are you using on Heroku? Is there a load balancer or some other router on Heroku that's serving your node server out? - richardgirges
Have you managed to resolve this? - haxpanel