express-mongo-stream
v1.0.3
Published
Stream files from MongoDB GridFS to expressjs.
Downloads
2
Readme
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' }