Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @ Upload File to MongoDB
- import { Context } from 'moleculer';
- export const upload = {
- handler(ctx: Context) {
- return new Promise((resolve, reject) => {
- const uploadStream = this.gridFSBucket.openUploadStream(ctx.meta.filename, {
- contentType: ctx.meta.type,
- });
- uploadStream
- .once('finish', () => {
- resolve(uploadStream.id);
- })
- .once('error', err => {
- ctx.broker.logger.error(err);
- reject(err);
- });
- ctx.params.pipe(uploadStream);
- });
- },
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement