Thursday, 3 September 2020

I need help streaming videos with Minio s3 compatible bucket, expressjs, and possibly nginx

I want to stream a video saved in an s3 bucket. I'm using minio as an s3 compatible client and the whole server sits behind nginx. Whenever I try streaming the video using chrome the player shows blank, leaving no explanation. Here's my code:const range = require('express-range') const route = require('express').Router() const s3Client = new require('@streamplace/minio).Client({ ...secrets }) // mountVideo is a middleware that produces req.s3ObjectName using req.params.id route.get('/:id/stream', mountVideo, range({ accept: 'bytes' }), (req, res) => { s3Client.statObject('videos', req.s3ObjectName, (err, stat) => { if (err) { if (err.code === 'NotFound') { console.log('Not found') res.sendStatus(404) } else { console.log('Error', err) res.status(500).json(err) } } else { res.set('Content-Type', stat.contentType) res.set('Content-Length', `${stat.size - req.range.first}`) res.set('Content-Range', `bytes ${req.range.first}-${stat.size}/${stat.size}`) res.set('Accept-Ranges', 'bytes') s3Client.getObject('videos', req.s3ObjectName, (err, stream) => { console.log('Streaming video', req.s3ObjectName) stream.pipe(res) }) } }) }) I followed the exact way method of streaming a file I found in this stackoverflow answer substituting the fs filestream for the minio getObject. I also did some research thinking that nginx was interfering, so I added these lines to my nginx.confhttp { ... client_max_body_size 0; proxy_max_temp_file_size 0; proxy_buffering off; ... } Can somebody help me out. I don't know what to do without an error message.

Submitted September 04, 2020 at 04:50AM by danhab99

No comments:

Post a Comment