I am trying to upload videos from android/IOS client to NodeJS Server. It works fine for smaller videos but when i try to upload a video lets say, larger than 50 MBs, it throws server timeout error.
One possible solution in my mind is to increase the server timeout limit, but that doesn't seem to be a proper solution. Is there a proper way to upload videos from android without any limitation?
Here is the code that i am using.
exports.create = function(req, res) {
req.setTimeout(0);
var storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, config.uploads.videoUpload.dest);
},
filename: function (req, file, cb) {
let extArray = file.mimetype.split("/");
let extension = extArray[extArray.length - 1];
cb(null, Date.now()+ '.' +extension);
}
});
var upload = multer({
storage: storage,
limits: config.uploads.videoUpload.limits,
fileFilter: function (req, file, cb)
{
if (file.mimetype !== 'image/jpeg' && file.mimetype !== 'video/mp4')
{
return res.status(400).send({
message: 'Only video files are allowed!',
error: true
});
}
cb(null, true);
}
}).single('video_file');
if (user)
{
// upload function with a callback
upload(req, res, function(uploadError) {
if (uploadError)
{
return res.status(400).send({
message: 'Error occurred while uploading Video',
error: true
});
}
else
{
return res.status(200).send({
message: 'Video uploaded Successfuly!',
error: false
});
}
});
}
else
{
res.status(400).send({
message: 'User is not signed in',
error: true
});
}
};