- Reference >
- MongoDB\GridFS\Bucket Class >
- MongoDB\GridFS\Bucket::openUploadStream()
MongoDB\GridFS\Bucket::openUploadStream()
On this page
Definition
-
MongoDB\GridFS\Bucket::openUploadStream Opens a writable stream for a new GridFS file.
This method has the following parameters:
Parameter Type Description $filenamestring The filenameof the file.$optionsarray Optional. An array specifying the desired options. The
$optionsparameter supports the following options:Option Type Description _idmixed Optional. Value to use as the file document identifier. Defaults to a new MongoDB\BSON\ObjectId object. chunkSizeBytesinteger Optional. The chunk size in bytes. Defaults to the bucket’s chunkSizeBytesoption.disableMD5boolean Optional. Whether to disable automatic MD5 generation when storing files.
Defaults to
false.metadataarray|object Optional. User data for the metadatafield of the file document. If not specified, themetadatafield will not be set on the file document.
Return Values
A writable stream resource.
Behavior
Chunk documents will be created as data is written to the writable stream. The metadata document will be created when the writable stream is closed.
Examples
The output would then resemble:
string(6) "foobar"