I'm using mongoose with gridfs-stream to store files, images, audios, and videos.
The problem is when I select another position/time in the video, is stopped, the same happens when I play any song.
Someone can help me?
This is my code:
exports.readById = function(req, res) {
var id = req.modelName._id;
gfs.findOne({
_id: id
}, function(err, file) {
if (err) {
return res.status(400).send({
err: errorHandler.getErrorMessage(err)
});
}
if (!file) {
return res.status(404).send({
err: 'No se encontró el registro especificado.'
});
}
res.writeHead(200, {
'Accept-Ranges': 'bytes',
'Content-Length': file.length,
'Content-Type': file.contentType
});
var readStream = gfs.createReadStream({
_id: file._id
});
readStream.on('error', function(err) {
if (err) {
return res.status(400).send({
err: errorHandler.getErrorMessage(err)
});
}
});
readStream.pipe(res);
});
};