MongoDB\GridFS\Bucket::openUploadStream()
Definition
Parameters
$filename
: string- The
filename
of the file to create. $options
: arrayAn array specifying the desired options.
NameTypeDescription_idmixedValue to use as the file document identifier. Defaults to a new MongoDB\BSON\ObjectId object.chunkSizeBytesintegerThe chunk size in bytes. Defaults to the bucket'schunkSizeBytes
option.disableMD5booleanWhether to disable automatic MD5 generation when storing files.
Defaults to
false
. Onlytrue
will be supported in 2.0.New in version 1.4.
metadataarray|objectUser data for themetadata
field of the file document. If not specified, themetadata
field 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
$bucket = (new MongoDB\Client)->test->selectGridFSBucket(); $uploadStream = $bucket->openUploadStream('filename'); fwrite($uploadStream, 'foobar'); fclose($uploadStream); $downloadStream = $bucket->openDownloadStreamByName('filename'); var_dump(stream_get_contents($downloadStream));
The output would then resemble:
string(6) "foobar"