public function copyToBlob(BlobFile $objFile)
 {
     if ($this->exists_blob($objFile)) {
         $this->outLog('exists_blob');
         $objBlobMetadataResult = $this->blobRestProxy->getBlobMetadata($this->containerName, 'save_image/' . $objFile->file_name);
         $arrMetadata = $objBlobMetadataResult->getMetadata();
         if ($arrMetadata['mtime'] == $objFile->getMtime()) {
             $this->outLog('equals');
             return;
         } elseif ($arrMetadata['mtime'] > $objFile->getMtime()) {
             $result = file_put_contents(IMAGE_SAVE_REALDIR . $objFile->file_name, ENDPOINT_PROTOCOL . '://' . AZURE_BLOB_ACCOUNT_NAME . '.blob.core.windows.net/' . $this->containerName . '/save_image/' . $objFile->file_name);
             $this->outLog($result);
         } else {
         }
     } else {
         try {
             $mimeType = $objFile->getMimeType();
             $this->outLog('create: ' . $objFile->file_name);
             $this->outLog('mimeType: ' . $mimeType);
             $createBlobOptions = new CreateBlobOptions();
             $createBlobOptions->setBlobContentType($mimeType);
             $createBlobOptions->setMetadata(array('mtime' => $objFile->getMtime()));
             $this->blobRestProxy->createBlockBlob($this->containerName, 'save_image/' . $objFile->file_name, $objFile->getResources(), $createBlobOptions);
         } catch (ServiceException $e) {
             $code = $e->getCode();
             $error_message = $e->getMessage();
             $this->outLog($code . ": " . $error_message . "<br />");
         }
     }
 }
예제 #2
0
 protected function createBlockBlob($filename, $data, $options)
 {
     $create_blob_options = new CreateBlobOptions();
     if (isset($options['mime'])) {
         $create_blob_options->setBlobContentType($options['mime']);
     }
     return $this->getBlobService()->createBlockBlob($options['container'], $filename, $data, $create_blob_options);
 }
예제 #3
0
파일: Admin.php 프로젝트: tooby93/Resepte
 public function actionAdd()
 {
     if (VF::app()->is_admin || isset($_GET['key']) && $_GET['key'] == 'eb4db0c51005d73ae57064be10c17145') {
         $new_id = 0;
         if (isset($_POST['title'])) {
             $title = trim(mysql_real_escape_string($_POST['title']));
             $lang_id = (int) $_POST['lang_id'];
             $category_id = (int) $_POST['category_id'];
             $holiday_id = (int) $_POST['holiday_id'];
             $instructions = trim(mysql_real_escape_string($_POST['instructions']));
             $prep_time = trim(mysql_real_escape_string($_POST['prep_time']));
             $cook_time = trim(mysql_real_escape_string($_POST['cook_time']));
             $total_time = trim(mysql_real_escape_string($_POST['total_time']));
             $ingredients = $_POST['ingredient'];
             $blob_name = '';
             if (!empty($_FILES['image']['tmp_name'])) {
                 $connectionString = "DefaultEndpointsProtocol=http;AccountName=trecipes;AccountKey=FoleK8mHGV5MaOvnJaZV6MFD7WadIEc12SL5hhwj7h949ysaXcp7VeTHimfQt6qxSwdQIEVkba0NQ/o58cgdXw==";
                 // Create blob REST proxy.
                 $blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString);
                 $options = new CreateBlobOptions();
                 $options->setBlobContentType("image/jpeg");
                 $blob_name = md5(time()) . ".jpg";
                 system("convert " . $_FILES['image']['tmp_name'] . " -resize 200x200 " . $_FILES['image']['tmp_name']);
                 $content = fopen($_FILES['image']['tmp_name'], "r");
                 $blobRestProxy->createBlockBlob("previews", $blob_name, $content, $options);
                 $blob_name = "http://s1.resepte.net/previews/{$blob_name}";
             }
             VF::app()->database->query("INSERT INTO recipes (title, image_url, image_mobile_url, category_id, instructions, lang_id,\n                prep_time, cook_time, total_time, holiday_id) VALUES ('{$title}', '{$blob_name}', '', {$category_id}, '{$instructions}', '{$lang_id}', '{$prep_time}', '{$cook_time}', '{$total_time}', {$holiday_id})\n                ");
             $new_id = VF::app()->database->getLastId();
             if ($new_id > 0) {
                 foreach ($ingredients as $i => $ing) {
                     $ing = mysql_real_escape_string(trim($ing));
                     if (!empty($ing)) {
                         $i_id = VF::app()->database->sql("SELECT id FROM `ingredients` WHERE name = '{$ing}'")->queryRow();
                         $i_id = (int) $i_id['id'];
                         if ($i_id == 0) {
                             VF::app()->database->query("INSERT INTO `ingredients` (name, lang_id) VALUES ('{$ing}', {$lang_id})");
                             $i_id = VF::app()->database->getLastId();
                         }
                         $amount = mysql_real_escape_string(trim($_POST['ingredient_append'][$i]));
                         VF::app()->database->query("INSERT INTO recipes2ingredients (recipe_id, ingredient_id, append) VALUES ('{$new_id}', '{$i_id}', '{$amount}')");
                     }
                 }
             }
         }
         $this->render('add', array('new_id' => $new_id));
     }
 }
예제 #4
0
 public function store($file, $id)
 {
     $blobOpts = new CreateBlobOptions();
     $blobOpts->setContentType($file->getMimeType());
     $blobOpts->setCacheControl('max-age=315360000');
     try {
         $img = new \Imagick($file->getRealPath());
         $this->blobRestProxy->createBlockBlob($this->container, $id, $img->getImagesBlob(), $blobOpts);
         $img->coalesceImages();
         foreach ($img as $frame) {
             $frame->thumbnailImage(180, 180);
             $frame->setImagePage(180, 180, 0, 0);
         }
         $this->blobRestProxy->createBlockBlob($this->container, $id . '.t', $img->getImagesBlob(), $blobOpts);
     } catch (\Exception $e) {
         return $e;
     }
     return null;
 }
 public function pn_blob_cache_set($key, $data, $expire, $headers)
 {
     $options = new CreateBlobOptions();
     //Set metadata and content-type for blob if header array was provided
     if ($this->prepare_headers($headers)) {
         if (isset($this->content_type)) {
             $options->setBlobContentType($this->content_type);
         }
         $options->setCacheControl("max-age=" . $expire);
         $options->setMetadata(array('Projectnamicacheduration' => $expire, 'Headers' => $this->headers_as_json));
     } else {
         $options->setMetadata(array('Projectnamicacheduration' => $expire));
     }
     try {
         //Upload blob
         $this->blob_service->createBlockBlob($this->container, $key, $data, $options);
         return true;
     } catch (ServiceException $e) {
         $this->pn_handle_exception($e);
     }
 }
예제 #6
0
 /**
  * Загрузка Blob в контейнер
  * 
  * @param type $filepath
  * @return boolean
  * @throws Exception
  */
 public function create($filepath)
 {
     $this->setFilePath($filepath);
     $this->createContainerIfPossible();
     $fullpath = "{$this->filePrefix}/{$this->filepath}";
     // возвращает mime-тип
     $finfo = finfo_open(FILEINFO_MIME_TYPE);
     $mime = finfo_file($finfo, $fullpath);
     finfo_close($finfo);
     if (!$mime) {
         throw new Exception("Not found mime-type: {$fullpath}");
     }
     $content = fopen($fullpath, "r");
     if (!$content) {
         throw new Exception("Cant open file: {$fullpath}");
     }
     $options = new CreateBlobOptions();
     $options->setBlobContentType($mime);
     //Передача blob-объекта
     $this->blobRestProxy->createBlockBlob($this->containerName, $this->blobName, $content, $options);
     return true;
 }
예제 #7
0
 /**
  * Creates a new page blob. Note that calling createPageBlob to create a page
  * blob only initializes the blob.
  * To add content to a page blob, call createBlobPages method.
  * 
  * @param string                   $container The container name.
  * @param string                   $blob      The blob name.
  * @param integer                  $length    Specifies the maximum size for the
  * page blob, up to 1 TB. The page blob size must be aligned to a 512-byte 
  * boundary.
  * @param Models\CreateBlobOptions $options   The optional parameters.
  * 
  * @return CopyBlobResult
  * 
  * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179451.aspx
  */
 public function createPageBlob($container, $blob, $length, $options = null)
 {
     Validate::isString($container, 'container');
     Validate::isString($blob, 'blob');
     Validate::notNullOrEmpty($blob, 'blob');
     Validate::isInteger($length, 'length');
     Validate::notNull($length, 'length');
     $method = Resources::HTTP_PUT;
     $headers = array();
     $postParams = array();
     $queryParams = array();
     $path = $this->_createPath($container, $blob);
     $statusCode = Resources::STATUS_CREATED;
     if (is_null($options)) {
         $options = new CreateBlobOptions();
     }
     $this->addOptionalHeader($headers, Resources::X_MS_BLOB_TYPE, BlobType::PAGE_BLOB);
     $this->addOptionalHeader($headers, Resources::X_MS_BLOB_CONTENT_LENGTH, $length);
     $this->addOptionalHeader($headers, Resources::X_MS_BLOB_SEQUENCE_NUMBER, $options->getSequenceNumber());
     $headers = $this->_addCreateBlobOptionalHeaders($options, $headers);
     $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout());
     $response = $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode);
     return CopyBlobResult::create($response->getHeader());
 }
 public static function getInterestingCreateBlobOptions()
 {
     $ret = array();
     $options = new CreateBlobOptions();
     array_push($ret, $options);
     $options = new CreateBlobOptions();
     $options->setTimeout(10);
     array_push($ret, $options);
     $options = new CreateBlobOptions();
     $options->setTimeout(-10);
     array_push($ret, $options);
     $options = new CreateBlobOptions();
     $metadata = array('foo' => 'bar', 'foo2' => 'bar2', 'foo3' => 'bar3');
     $options->setMetadata($metadata);
     $options->setTimeout(10);
     array_push($ret, $options);
     $options = new CreateBlobOptions();
     $metadata = array('foo' => 'bar');
     $options->setMetadata($metadata);
     $options->setTimeout(-10);
     array_push($ret, $options);
     return $ret;
 }
예제 #9
0
 /**
  * Uploads the channel files to blob storage.
  *
  * @return none
  *
  * @throws \Exception
  */
 private static function _uploadChannel()
 {
     $names = array();
     self::_rscandir('channel', $names);
     $contents = array_map('file_get_contents', $names);
     echo "Uploading channel files to the cloud...\n";
     self::_tryCreateContainer(CHANNEL_MAIN_CONTAINER);
     self::_tryCreateContainer(CHANNEL_GET_CONTAINER);
     self::_tryCreateContainer(CHANNEL_REST_CONTAINER);
     $channelDir = 'channel/';
     $getDir = $channelDir . 'get/';
     $restDir = $channelDir . 'rest/';
     for ($i = 0; $i < count($names); $i++) {
         $options = new CreateBlobOptions();
         $finfo = finfo_open(FILEINFO_MIME_TYPE);
         $options->setContentType(finfo_file($finfo, $names[$i]));
         if (strpos($names[$i], $getDir) !== false) {
             $names[$i] = str_replace($getDir, '', $names[$i]);
             $container = CHANNEL_GET_CONTAINER;
         } else {
             if (strpos($names[$i], $restDir) !== false) {
                 $names[$i] = str_replace($restDir, '', $names[$i]);
                 $container = CHANNEL_REST_CONTAINER;
             } else {
                 if (strpos($names[$i], $channelDir) !== false) {
                     $names[$i] = str_replace($channelDir, '', $names[$i]);
                     $container = CHANNEL_MAIN_CONTAINER;
                 } else {
                     throw new \Exception('incorrect file path.');
                 }
             }
         }
         self::$_blobRestProxy->createBlockBlob($container, $names[$i], $contents[$i], $options);
     }
 }
예제 #10
0
 /**
  * @covers WindowsAzure\Blob\BlobRestProxy::breakLease
  * @covers WindowsAzure\Blob\BlobRestProxy::_putLeaseImpl
  */
 public function testBreakLease()
 {
     // Setup
     $name = 'breaklease';
     $blob = 'myblob';
     $contentType = 'text/plain; charset=UTF-8';
     $this->createContainer($name);
     $options = new CreateBlobOptions();
     $options->setContentType($contentType);
     $this->restProxy->createBlockBlob($name, $blob, 'Hello world', $options);
     $result = $this->restProxy->acquireLease($name, $blob);
     // Test
     $this->restProxy->breakLease($name, $blob, $result->getLeaseId());
     // Assert
     $this->setExpectedException(get_class(new ServiceException('')));
     $result = $this->restProxy->acquireLease($name, $blob);
 }
예제 #11
0
 /**
  * @param string $container
  * @param string $name
  * @param string $blob
  * @param string $type
  *
  * @return void
  */
 public function putBlobData($container, $name, $blob = '', $type = '')
 {
     $this->checkConnection();
     $options = new CreateBlobOptions();
     if (!empty($type)) {
         $options->setContentType($type);
     }
     $this->blobConn->createBlockBlob($container, $this->fixBlobName($name), $blob, $options);
 }
예제 #12
0
파일: Api.php 프로젝트: tooby93/Resepte
 public function actionUploadPhoto()
 {
     file_put_contents("/var/log/nginx/test/1.txt", print_r($_REQUEST), FILE_APPEND);
     if (isset($_GET['recipe_id']) && (int) $_GET['recipe_id'] > 0 && isset($_GET['user_id']) && (int) $_GET['user_id'] > 0 && !empty($_FILES['uploaded_file'])) {
         $id = (int) $_GET['recipe_id'];
         $user_id = (int) $_GET['user_id'];
         $connectionString = "DefaultEndpointsProtocol=http;AccountName=trecipes;AccountKey=FoleK8mHGV5MaOvnJaZV6MFD7WadIEc12SL5hhwj7h949ysaXcp7VeTHimfQt6qxSwdQIEVkba0NQ/o58cgdXw==";
         // Create blob REST proxy.
         $blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString);
         $options = new CreateBlobOptions();
         $options->setBlobContentType("image/jpeg");
         $blob_name = md5(time()) . ".jpg";
         //system("convert ".$_FILES['uploaded_file']['tmp_name']." -resize 600x600 ".$_FILES['uploaded_file']['tmp_name']);
         $content = fopen($_FILES['uploaded_file']['tmp_name'], "r");
         $blobRestProxy->createBlockBlob("photos", $blob_name, $content, $options);
         VF::app()->database->query("INSERT INTO recipes_photos (recipe_id, user_id, url) VALUES ({$id},{$user_id},'http://s1.resepte.net/photos/{$blob_name}')");
     }
 }
 /**
  * @covers WindowsAzure\Blob\BlobRestProxy::createPageBlob
  * @covers WindowsAzure\Blob\BlobRestProxy::getBlobMetadata
  */
 public function testGetBlobMetadataWorks()
 {
     // Act
     $container = self::$_test_container_for_blobs;
     $blob = 'test';
     $opts = new CreateBlobOptions();
     $metadata = $opts->getMetadata();
     $metadata['test'] = 'bar';
     $metadata['blah'] = 'bleah';
     $opts->setMetadata($metadata);
     $this->restProxy->createPageBlob($container, $blob, 4096, $opts);
     $props = $this->restProxy->getBlobMetadata($container, $blob);
     // Assert
     $this->assertNotNull($props, '$props');
     $this->assertNotNull($props->getETag(), '$props->getETag()');
     $this->assertNotNull($props->getMetadata(), '$props->getMetadata()');
     $this->assertEquals(2, count($props->getMetadata()), 'count($props->getMetadata())');
     $this->assertTrue(Utilities::arrayKeyExistsInsensitive('test', $props->getMetadata()), 'Utilities::arrayKeyExistsInsensitive(\'test\', $props->getMetadata())');
     $this->assertTrue(!(array_search('bar', $props->getMetadata()) === FALSE), '!(array_search(\'bar\', $props->getMetadata()) === FALSE)');
     $this->assertTrue(Utilities::arrayKeyExistsInsensitive('blah', $props->getMetadata()), 'Utilities::arrayKeyExistsInsensitive(\'blah\', $props->getMetadata())');
     $this->assertTrue(!(array_search('bleah', $props->getMetadata()) === FALSE), '!(array_search(\'bleah\', $props->getMetadata()) === FALSE)');
     $this->assertNotNull($props->getLastModified(), '$props->getLastModified()');
 }
 /**
  * Upload the given file to an azure storage container as a block blob.
  * Block blobs let us upload large blobs efficiently. Block blobs are comprised of blocks,
  * each of which is identified by a block ID. This allows create (or modify) a block blob
  * by writing a set of blocks and committing them by their block IDs.
  * If we are writing a block blob that is no more than 64 MB in size, you can upload it
  * in its entirety with a single write operation.
  * When you upload a block to a blob in your storage account, it is associated with the
  * specified block blob, but it does  not become part of the blob until you commit a list
  * of blocks that includes the new block's ID.
  *
  * @param string            $containerName      Container name
  *
  * @param string            $blobName           Blob name
  *
  * @param string            $localFileName      Path to local file to be uploaded
  *
  * @param string            $blobContentType    Content type of the blob
  *
  * @param array             $metadata           Array of metadata
  *
  * @return void
  *
  * @throws ServiceException
  */
 public static function putBlockBlob($containerName, $blobName, $localFileName, $blobContentType = null, $metadata = array())
 {
     $copyBlobResult = null;
     // Open file
     $handle = fopen($localFileName, 'r');
     if ($handle === false) {
         throw new Exception('Could not open the local file ' . localFileName);
     }
     $blobRestProxy = WindowsAzureStorageUtil::getStorageClient();
     try {
         if (filesize($localFileName) < self::MAX_BLOB_SIZE) {
             $createBlobOptions = new CreateBlobOptions();
             $createBlobOptions->setBlobContentType($blobContentType);
             $createBlobOptions->setMetadata($metadata);
             $blobRestProxy->createBlockBlob($containerName, $blobName, $handle, $createBlobOptions);
             fclose($handle);
         } else {
             // Determine number of page blocks
             $numberOfBlocks = ceil(filesize($localFileName) / self::MAX_BLOB_TRANSFER_SIZE);
             // Generate block id's
             $blocks = array();
             for ($i = 0; $i < $numberOfBlocks; $i++) {
                 $blocks[$i] = new Block();
                 $blocks[$i]->setBlockId(self::_generateBlockId($i));
                 $blocks[$i]->setType(BlobBlockType::LATEST_TYPE);
             }
             // Upload blocks
             for ($i = 0; $i < $numberOfBlocks; $i++) {
                 // Seek position in file
                 fseek($handle, $i * self::MAX_BLOB_TRANSFER_SIZE);
                 // Read contents
                 $fileContents = fread($handle, self::MAX_BLOB_TRANSFER_SIZE);
                 // Put block
                 $blobRestProxy->createBlobBlock($containerName, $blobName, $blocks[$i]->getBlockId(), $fileContents);
                 // Dispose file contents
                 $fileContents = null;
                 unset($fileContents);
             }
             // Close file
             fclose($handle);
             // Set Block Blob's content type and metadata
             $commitBlockBlobOptions = new CommitBlobBlocksOptions();
             $commitBlockBlobOptions->setBlobContentType($blobContentType);
             $commitBlockBlobOptions->setMetadata($metadata);
             // Commit the block list
             $blobRestProxy->commitBlobBlocks($containerName, $blobName, $blocks, $commitBlockBlobOptions);
         }
     } catch (ServiceException $exception) {
         if (!$handle) {
             fclose($handle);
         }
         throw $exception;
     }
 }
 /**
  * Upload the given file to an Azure Storage container as a block blob.
  *
  * Block blobs are comprised of blocks, each of which is identified by a block ID.
  * This allows creation or modification of a block blob by writing a set of blocks
  * and committing them by their block IDs, resulting in an overall efficient upload.
  *
  * If writing a block blob that is no more than 64MB in size, upload it
  * in its entirety with a single write operation. Otherwise, chunk the blob into discrete
  * blocks and upload each of them, then commit the blob ID to signal to Azure that they
  * should be combined into a blob. Files over 64MB are then deleted from temporary local storage.
  *
  * When you upload a block to a blob in your storage account, it is associated with the
  * specified block blob, but it does  not become part of the blob until you commit a list
  * of blocks that includes the new block's ID.
  *
  * @param string $containerName   The container to add the blob to.
  * @param string $blobName        The name of the blob to upload.
  * @param string $localFileName   The full path to local file to be uploaded.
  * @param string $blobContentType Optional. Content type of the blob.
  * @param array  $metadata        Optional. Metadata to describe the blob.
  *
  * @throws \Exception|ServiceException Exception if local file can't be read;
  *                                     ServiceException if response code is incorrect.
  */
 public static function putBlockBlob($containerName, $blobName, $localFileName, $blobContentType = null, $metadata = array())
 {
     $copyBlobResult = null;
     $is_large_file = false;
     // Open file
     $handle = fopen($localFileName, 'r');
     if ($handle === false) {
         throw new Exception('Could not open the local file ' . $localFileName);
     }
     /** @var \WindowsAzure\Blob\BlobRestProxy $blobRestProxy */
     $blobRestProxy = WindowsAzureStorageUtil::getStorageClient();
     try {
         if (filesize($localFileName) < self::MAX_BLOB_SIZE) {
             $createBlobOptions = new CreateBlobOptions();
             $createBlobOptions->setBlobContentType($blobContentType);
             $createBlobOptions->setMetadata($metadata);
             $blobRestProxy->createBlockBlob($containerName, $blobName, $handle, $createBlobOptions);
             fclose($handle);
         } else {
             $is_large_file = true;
             // Determine number of page blocks
             $numberOfBlocks = ceil(filesize($localFileName) / self::MAX_BLOB_TRANSFER_SIZE);
             // Generate block id's
             $blocks = array();
             for ($i = 0; $i < $numberOfBlocks; $i++) {
                 /** @var WindowsAzure\Blob\Models\Block */
                 $block = new Block();
                 $block->setBlockId(self::_generateBlockId($i));
                 $block->setType(BlobBlockType::LATEST_TYPE);
                 // Seek position in file
                 fseek($handle, $i * self::MAX_BLOB_TRANSFER_SIZE);
                 // Read contents
                 $fileContents = fread($handle, self::MAX_BLOB_TRANSFER_SIZE);
                 // Put block
                 $blobRestProxy->createBlobBlock($containerName, $blobName, $block->getBlockId(), $fileContents);
                 // Save it for later
                 $blocks[$i] = $block;
             }
             // Close file
             fclose($handle);
             // Set Block Blob's content type and metadata
             $commitBlockBlobOptions = new CommitBlobBlocksOptions();
             $commitBlockBlobOptions->setBlobContentType($blobContentType);
             $commitBlockBlobOptions->setMetadata($metadata);
             // Commit the block list
             $blobRestProxy->commitBlobBlocks($containerName, $blobName, $blocks, $commitBlockBlobOptions);
             if ($is_large_file) {
                 // Delete large temp files when we're done
                 try {
                     //TODO: add option to keep this file if so desired
                     if (self::blob_exists_in_container($blobName, $containerName)) {
                         wp_delete_file($localFileName);
                         // Dispose file contents
                         $fileContents = null;
                         unset($fileContents);
                     } else {
                         throw new Exception(sprintf(__('The blob %1$2 was not uploaded to container %2$2. Please try again.', 'windows-azure-storage'), $blobName, $containerName));
                     }
                 } catch (Exception $ex) {
                     echo '<p class="notice">' . esc_html($ex->getMessage()) . '</p>';
                 }
             }
         }
     } catch (ServiceException $exception) {
         if (!$handle) {
             fclose($handle);
         }
         throw $exception;
     }
 }
예제 #16
0
 /**
  * {@inheritDoc}
  */
 public function write($key, $content)
 {
     $this->init();
     try {
         $options = new CreateBlobOptions();
         if ($this->detectContentType) {
             $fileInfo = new \finfo(FILEINFO_MIME_TYPE);
             $contentType = $fileInfo->buffer($content);
             $options->setContentType($contentType);
         }
         $this->blobProxy->createBlockBlob($this->containerName, $key, $content, $options);
         return Util\Size::fromContent($content);
     } catch (ServiceException $e) {
         $this->failIfContainerNotFound($e, sprintf('write content for key "%s"', $key));
         return false;
     }
 }
예제 #17
0
 /**
  * Retrieve options from a Config instance.
  *
  * @param Config $config
  *
  * @return CreateBlobOptions
  */
 protected function getOptionsFromConfig(Config $config)
 {
     $options = new CreateBlobOptions();
     foreach (static::$metaOptions as $option) {
         if (!$config->has($option)) {
             continue;
         }
         call_user_func([$options, "set{$option}"], $config->get($option));
     }
     if ($mimetype = $config->get('mimetype')) {
         $options->setContentType($mimetype);
     }
     return $options;
 }
 /**
  * @covers WindowsAzure\Blob\BlobRestProxy::createBlockBlob
  **/
 public function testCreateBlobLargerThanSingleBlock()
 {
     // First step, lets set the value for automagic splitting to somethign very small
     $max_size = 50;
     $this->restProxy->setSingleBlobUploadThresholdInBytes($max_size);
     $this->assertEquals($this->restProxy->getSingleBlobUploadThresholdInBytes(), $max_size);
     $name = 'createbloblargerthansingleblock' . $this->createSuffix();
     $this->createContainer($name);
     $contentType = 'text/plain; charset=UTF-8';
     $content = "This is a really long section of text needed for this test.";
     // Note this grows fast, each loop doubles the last run. Do not make too big
     // This results in a 1888 byte string, divided by 50 results in 38 blocks
     for ($i = 0; $i < 5; $i++) {
         $content .= $content;
     }
     $options = new CreateBlobOptions();
     $options->setContentType($contentType);
     $this->restProxy->createBlockBlob($name, 'little_split', $content, $options);
     // Block specific
     $boptions = new ListBlobBlocksOptions();
     $boptions->setIncludeUncommittedBlobs(true);
     $boptions->setIncludeCommittedBlobs(true);
     $result = $this->restProxy->listBlobBlocks($name, 'little_split', $boptions);
     $blocks = $result->getUnCommittedBlocks();
     $this->assertEquals(count($blocks), 0);
     $blocks = $result->getCommittedBlocks();
     $this->assertEquals(count($blocks), ceil(strlen($content) / $max_size));
     // Setting back to default value for one shot test
     $this->restProxy->setSingleBlobUploadThresholdInBytes(0);
     $this->restProxy->createBlockBlob($name, 'oneshot', $content, $options);
     $result = $this->restProxy->listBlobBlocks($name, 'oneshot', $boptions);
     $blocks = $result->getUnCommittedBlocks();
     $this->assertEquals(count($blocks), 0);
     $blocks = $result->getCommittedBlocks();
     // this one doesn't make sense. On emulator, there is no block created,
     // so relying on content size to be final approval
     $this->assertEquals(count($blocks), 0);
     $this->assertEquals($result->getContentLength(), strlen($content));
     // make string even larger for automagic splitting
     // This should result in a string longer than 32M, and force the blob into 2 blocks
     for ($i = 0; $i < 15; $i++) {
         $content .= $content;
     }
     $this->restProxy->createBlockBlob($name, 'bigsplit', $content, $options);
     $result = $this->restProxy->listBlobBlocks($name, 'bigsplit', $boptions);
     $blocks = $result->getUnCommittedBlocks();
     $this->assertEquals(count($blocks), 0);
     $blocks = $result->getCommittedBlocks();
     $this->assertEquals(count($blocks), ceil(strlen($content) / (4 * 1024 * 1024)));
 }
 /**
  * @covers WindowsAzure\Blob\Models\CreateBlobOptions::setAccessCondition
  */
 public function testSetAccessCondition()
 {
     // Setup
     $expected = AccessCondition::none();
     $result = new CreateBlobOptions();
     // Test
     $result->setAccessCondition($expected);
     // Assert
     $this->assertEquals($expected, $result->getAccessCondition());
 }