- Reference >
- MongoDB\GridFS\Bucket Class >
- MongoDB\GridFS\Bucket::downloadToStream()
MongoDB\GridFS\Bucket::downloadToStream()
On this page
Definition
-
MongoDB\GridFS\Bucket::downloadToStream Selects a GridFS file by its
_idand copies its contents to a writable stream.This method has the following parameters:
Parameter Type Description $idmixed The _idof the file.$destinationresource Writable stream, to which the GridFS file’s contents will be written.
Errors/Exceptions
MongoDB\GridFS\Exception\FileNotFoundException if no file was
found for the selection criteria.
MongoDB\Exception\InvalidArgumentException for errors related to
the parsing of parameters or options.
MongoDB\Driver\Exception\RuntimeException for other errors at the driver level (e.g. connection errors).
Examples
The output would then resemble:
string(6) "foobar"