/**
  * @covers WindowsAzure\Blob\Models\CreateBlobOptions::setContentType
  * @covers WindowsAzure\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());
 }
Пример #2
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;
 }
 /**
  * @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)));
 }
Пример #4
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;
     }
 }
Пример #5
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);
     }
 }
 /**
  * @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);
 }
Пример #7
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;
 }
Пример #8
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);
 }
 /**
  * @covers WindowsAzure\Blob\BlobRestProxy::createPageBlob
  * @covers WindowsAzure\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())');
 }