Home > mongoose-gridfs-extra > writeFileWithStream
writeFileWithStream store a file into gridFS bucket using the provided stream. This function will overwrite the
Signature:
declare function writeFileWithStream(uploadStream: mongo.GridFSBucketWriteStream, file: Buffer): Promise<mongo.GridFSFile>;
| Parameter | Type | Description |
|---|---|---|
| uploadStream | mongo.GridFSBucketWriteStream | The stream to upload file to mongodb |
| file | Buffer | the file to save into mongodb bucket |
Returns:
Promise<mongo.GridFSFile>
a promise that resolves to a GridFSFile
Error
const uploadStream = bucket.openUploadStream(“example.txt”) ; const gridFsFile = await writeFileWithStream(uploadStream, file) ;