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.