1.0.3 • Published 5 years ago

express-mongo-stream v1.0.3

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

express-mongo-stream

Stream files from MongoDB GridFS to expressjs.

Installation

npm install express-mongo-stream

Usage

typescript

import {expressMongoStream, MongoFileParams} from 'express-mongo-stream';

app.get('/videos/:id', (req: Request, res: Response, next: any) => {

db.fs.findOne({_id: Types.ObjectId(req.params.id)})
	.then(file => {
		if (!file)
			return next();

		const params: MongoFileParams = {
			id: file.id,
			contentType: file.contentType,
			length: file.length,
			mtime: file.mtime,
			disposition: 'inline',
			duration: file.duration,
			ns: 'fs'
		};
		
		expressMongoStream(params, db, req, res);
	});

});

javascript

@todo

MongoFileParams

interface MongoFileParams { id: any; mtime: Date; length: number; contentType?: string; filename?: string; duration?: number; disposition?: 'attachment' | 'inline'; // default: 'inline' expireDays?: number; // default: 60 ns?: string; // default: 'fs' }