diff --git a/routes/videoRoutes.js b/routes/videoRoutes.js index 511778e..2a14081 100644 --- a/routes/videoRoutes.js +++ b/routes/videoRoutes.js @@ -270,13 +270,17 @@ router.get('/videos/file/:video_id', (req, res) => { return res.status(400).json({ error: 'Video not yet produced' }); } const videoPath = video.video_file; - console.log('Video path:', videoPath); - fs.access(videoPath, fs.constants.F_OK, (err) => { - if (err) { - console.error('Video not found:', err); - return res.status(404).json({ error: 'Video not found' }); - } - res.download(videoPath); + const fileStream = fs.createReadStream(videoPath); + + res.writeHead(200, { + 'Content-Type': 'video/mp4', + 'Content-Disposition': `attachment; filename="${path.basename(videoPath)}"` + }); + fileStream.pipe(res); + + fileStream.on('error', (err) => { + console.error('File stream error:', err); + res.status(500).json({ error: 'Error streaming video' }); }); }); });