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;
 }
 /**
  * @covers MicrosoftAzure\Storage\Blob\Models\CreateBlobOptions::setAccessCondition
  */
 public function testSetAccessCondition()
 {
     // Setup
     $expected = AccessCondition::none();
     $result = new CreateBlobOptions();
     // Test
     $result->setAccessCondition($expected);
     // Assert
     $this->assertEquals($expected, $result->getAccessCondition());
 }
 /**
  * @param string $localFilePath
  * @param string $targetFolderIdentifier
  * @param string $newFileName
  * @param bool $removeOriginal
  * @return string
  */
 public function addFile($localFilePath, $targetFolderIdentifier, $newFileName = '', $removeOriginal = true)
 {
     if ($newFileName === '') {
         $newFileName = basename($localFilePath);
     }
     $targetFolderIdentifier = $this->normalizeFolderName($targetFolderIdentifier);
     $fileIdentifier = $targetFolderIdentifier . $newFileName;
     $fileInfo = finfo_open(FILEINFO_MIME_TYPE);
     $contentType = finfo_file($fileInfo, $localFilePath);
     finfo_close($fileInfo);
     $options = new CreateBlobOptions();
     $options->setContentType($contentType);
     $this->createObject($fileIdentifier, file_get_contents($localFilePath), $options);
     return $fileIdentifier;
 }
 /**
  * @return void
  */
 public function testAddFileSetsMimeTypeInfo()
 {
     $this->storageDriver->addFile($this->testFilePath, 'fileadmin/test');
     $options = new CreateBlobOptions();
     $options->setContentType('text/plain');
     $this->blobRestProxy->createBlockBlob('mycontainer', 'fileadmin/test/test.txt', Arg::any(), Arg::exact($options))->shouldHaveBeenCalled();
 }
 /**
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::createPageBlob
  * @covers MicrosoftAzure\Storage\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()');
 }
Ejemplo n.º 6
0
 /**
  * @covers MicrosoftAzure\Storage\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)));
 }
Ejemplo n.º 7
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;
     }
 }
Ejemplo n.º 8
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(HttpFormatter::formatHeaders($response->getHeaders()));
 }