/** * When uploading large files (+5GB), you need to upload the file as chunks using multibyte transfer. This method * sets up the transfer, and in order to execute the transfer, you need to call upload() on the returned object. * * @param array Options * @see \OpenCloud\ObjectStore\Upload\UploadBuilder::setOptions for a list of accepted options. * @throws \OpenCloud\Common\Exceptions\InvalidArgumentError * @return mixed */ public function setupObjectTransfer(array $options = array()) { // Name is required if (empty($options['name'])) { throw new Exceptions\InvalidArgumentError('You must provide a name.'); } // As is some form of entity body if (!empty($options['path']) && file_exists($options['path'])) { $body = fopen($options['path'], 'r+'); } elseif (!empty($options['body'])) { $body = $options['body']; } else { throw new Exceptions\InvalidArgumentError('You must provide either a readable path or a body'); } // Build upload $transfer = TransferBuilder::newInstance()->setOption('objectName', $options['name'])->setEntityBody(EntityBody::factory($body))->setContainer($this); // Add extra options if (!empty($options['metadata'])) { $transfer->setOption('metadata', $options['metadata']); } if (!empty($options['partSize'])) { $transfer->setOption('partSize', $options['partSize']); } if (!empty($options['concurrency'])) { $transfer->setOption('concurrency', $options['concurrency']); } if (!empty($options['progress'])) { $transfer->setOption('progress', $options['progress']); } return $transfer->build(); }
/** * @expectedException OpenCloud\Common\Exceptions\InvalidArgumentError */ public function test_Consecutive_Transfer_Fails_Without_Object_Name() { TransferBuilder::newInstance()->setOptions(array('objectName' => false))->setEntityBody(EntityBody::factory(str_repeat('A', 100)))->setContainer($this->container)->build(); }