Skip to content

Instantly share code, notes, and snippets.

const File = require('../models/file')
const fs = require('fs')
exports.getFile = async function (request, response) {
let file = null
try { file = await File.findById(request.params.id) } catch (err) {}
if (!file) {
return response.status(404).json({
"data": {
const File = require('../models/file')
const Busboy = require('busboy')
const fs = require('fs')
exports.newFile = function (request, response, next) {
var busboy = new Busboy({ headers: request.headers })
busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
if (fs.existsSync(`../datum/${filename}`)) {
return response.status(400).json({
const fs = require('fs')
const video = './videos/sample.mp4' // source video
let stat = fs.statSync(video)
let range = request.headers.range // will be undefined on first request
if (range) { // if the user is requesting to scrub to a point in the video
let [start, end] = range.replace(/bytes=/, '').split('-') // the incoming range typically looks like bytes=3214-5435, so extract the numbers out from the request
start = parseInt(start, 10) // check we are dealing with an integer
end = end ? parseInt(end, 10) : stat.size - 1 // a request can be for a segment, or could be 'bytes=324-' idicating from here, until the end of the video. Therefore end can be undefined.