mongoose-gridfs-extra

Home > mongoose-gridfs-extra > writeFileById

writeFileById() function

readFileByName stores file into gridFS bucket by id

Signature:

declare function writeFileById(bucket: mongo.GridFSBucket, id: mongo.ObjectId | string | number, file: Buffer, fileName: string, options?: mongo.GridFSBucketWriteStreamOptions | undefined): Promise<mongo.GridFSFile>;

Parameters

Parameter Type Description
bucket mongo.GridFSBucket a mongodb gridFS bucket
id mongo.ObjectId | string | number id of file to read
file Buffer the file to save into mongodb bucket
fileName string name of file to store
options mongo.GridFSBucketWriteStreamOptions | undefined (Optional) options for opening download stream

Returns:

Promise<mongo.GridFSFile>

a promise that resolves to a GridFSFile

Exceptions

Error