A Download object is usually created by calling [[Collection::get()]] or [[Collection::createDownload()]]. Usage example: php Yii::$app->mongodb->getFileCollection()->createDownload($document['_id'])->toFile('/path/to/file.dat'); You can use Download::substr() to read a specific part of the file: php $filePart = Yii::$app->mongodb->getFileCollection()->createDownload($document['_id'])->substr(256, 1024);
Since: 2.1
Author: Paul Klimov (klimov.paul@gmail.com)
Inheritance: extends yii\base\Object
Example #1
0
 /**
  * Prepares [[Download]] instance for the read operations.
  * @return bool success.
  * @throws InvalidConfigException on invalid context configuration.
  */
 private function prepareDownload()
 {
     $contextOptions = $this->getContextOptions();
     if (isset($contextOptions[$this->protocol]['download'])) {
         $download = $contextOptions[$this->protocol]['download'];
         if (!$download instanceof Download) {
             throw new InvalidConfigException('"download" context option should be an instance of "' . Download::className() . '"');
         }
         $this->download = $download;
         return true;
     }
     $collection = $this->fetchCollection();
     if (empty($this->queryParams)) {
         return false;
     }
     $file = $collection->findOne($this->queryParams);
     if (empty($file)) {
         throw new InvalidConfigException('Requested file does not exits.');
     }
     $this->download = $file['file'];
     return true;
 }