1

The moment I try to upload a file with heroku to the database it won't work.

If I do it with localhost it does work.

Anybody has an idea why heroku is not handling my file when I try to upload a file to it? Does someone know a fix? I am kind of new to Heroku, and since I get no error in the logs I don't know what is going wrong.

The following is my code:

function addVideo(req, res) {
    console.log(req.files);
    User.findOne({ 'userName' : req.params.username }, function (err, user) {
        var video = new Video();
        video.sporter = user;
        video.save()
            .then(video => {
                vid = video;
                console.log(vid);
                upload(req, res, function(err) {
                    if (err)
                        handleError(req, res, 500, err);
                });
                res.status(201).json(video);
             })
            .fail(err => handleError(req, res, 500, err));
    });
}
var storage = GridFsStorage({
    gfs : gfs,
    chunkSize: 32740 ,
    filename: function (req, file, cb) {
        console.log(file);
        cb(null, vid._id);
    },
    /** With gridfs we can store additional meta-data along with the file */
    metadata: function(req, file, cb) {
        console.log(vid);
        cb(null,
            {   originalname: file.originalname,
                videoId: vid._id
            });
    },
    root: 'ctFiles' //root name for collection to store files into
});

var upload = multer({ //multer settings for single upload
    storage: storage
}).single('file');

As u see in my code, I create a new video, which I link to through my metadata. It does create a new Video model, but it doesn't create a new ctFiles.files object.

Markie Doe
  • 115
  • 1
  • 9
  • Hi Markie Doe - can you give some more details of how it does not work? For example, an MVCE [Minimal, Complete, and Verifiable Example](https://stackoverflow.com/help/mcve), and details of the error messages are other indicators that something is not working? – Vince Bowdren Jun 15 '17 at 11:03
  • The problem is I get no errors in my log. I had a h13 heroku error before, which probably happened because I uploaded too big chunks. I did change the chuncksize and now this error is gone, but it's still not working. I will upload some code. – Markie Doe Jun 15 '17 at 11:08

0 Answers0