/**
  * @covers MicrosoftAzure\Storage\Blob\Models\CreateBlobOptions::setContentType
  * @covers MicrosoftAzure\Storage\Blob\Models\CreateBlobOptions::getContentType
  */
 public function testSetContentType()
 {
     // Setup
     $expected = '0x8CAFB82EFF70C46';
     $options = new CreateBlobOptions();
     $options->setContentType($expected);
     // Test
     $options->setContentType($expected);
     // Assert
     $this->assertEquals($expected, $options->getContentType());
 }
 /**
  * @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::getBlob
  */
 public function testGetPageBlobWorks()
 {
     // Act
     $opts = new CreateBlobOptions();
     $opts->setBlobCacheControl('test');
     $opts->setBlobContentEncoding('UTF-8');
     $opts->setBlobContentLanguage('en-us');
     // $opts->setBlobContentMD5('1234');
     $opts->setBlobContentType('text/plain');
     $opts->setCacheControl('test');
     $opts->setContentEncoding('UTF-8');
     // $opts->setContentMD5('1234');
     $opts->setContentType('text/plain');
     $this->restProxy->createPageBlob(self::$_test_container_for_blobs, 'test', 4096, $opts);
     $result = $this->restProxy->getBlob(self::$_test_container_for_blobs, 'test');
     // Assert
     $this->assertNotNull($result, '$result');
     $this->assertNotNull($result->getMetadata(), '$result->getMetadata()');
     $this->assertEquals(0, count($result->getMetadata()), 'count($result->getMetadata())');
     $props = $result->getProperties();
     $this->assertEquals('test', $props->getCacheControl(), '$props->getCacheControl()');
     $this->assertEquals('UTF-8', $props->getContentEncoding(), '$props->getContentEncoding()');
     $this->assertEquals('en-us', $props->getContentLanguage(), '$props->getContentLanguage()');
     $this->assertEquals('text/plain', $props->getContentType(), '$props->getContentType()');
     $this->assertEquals(4096, $props->getContentLength(), '$props->getContentLength()');
     $this->assertNotNull($props->getETag(), '$props->getETag()');
     $this->assertNull($props->getContentMD5(), '$props->getContentMD5()');
     $this->assertNotNull($props->getLastModified(), '$props->getLastModified()');
     $this->assertEquals('PageBlob', $props->getBlobType(), '$props->getBlobType()');
     $this->assertEquals('unlocked', $props->getLeaseStatus(), '$props->getLeaseStatus()');
     $this->assertEquals(0, $props->getSequenceNumber(), '$props->getSequenceNumber()');
     $this->assertEquals(4096, strlen(stream_get_contents($result->getContentStream())), 'strlen($result->getContentStream())');
 }
Ejemplo n.º 5
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.º 6
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;
     }
 }