Phalcon\Db\Adapter\MongoDB\GridFS\WritableStream::uploadFromStream PHP Method

uploadFromStream() public method

Writes the contents of a readable stream to a GridFS file.
public uploadFromStream ( resource $source ) : MongoDB\BSON\ObjectId
$source resource Readable stream
return MongoDB\BSON\ObjectId
    public function uploadFromStream($source)
    {
        if (!is_resource($source) || get_resource_type($source) != "stream") {
            throw InvalidArgumentException::invalidType('$source', $source, 'resource');
        }
        while ($data = $this->readChunk($source)) {
            $this->insertChunk($data);
        }
        return $this->fileCollectionInsert();
    }

Usage Example

Beispiel #1
0
 /**
  * Writes the contents of a readable stream to a GridFS file.
  *
  * Supported options:
  *
  *  * chunkSizeBytes (integer): The chunk size in bytes. Defaults to the
  *    bucket's chunk size.
  *
  * @param string   $filename Filename
  * @param resource $source Readable stream
  * @param array    $options Stream options
  *
  * @return ObjectId ID of the newly created GridFS file
  * @throws InvalidArgumentException
  */
 public function uploadFromStream($filename, $source, array $options = [])
 {
     $options += ['chunkSizeBytes' => $this->options['chunkSizeBytes']];
     $stream = new WritableStream($this->collectionWrapper, $filename, $options);
     return $stream->uploadFromStream($source);
 }