示例#1
0
 /**
  * Reads or downloads a blob from the system, including its metadata and 
  * properties.
  * 
  * @param string                $container name of the container
  * @param string                $blob      name of the blob
  * @param Models\GetBlobOptions $options   optional parameters
  * 
  * @return Models\GetBlobResult
  * 
  * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179440.aspx
  */
 public function getBlob($container, $blob, $options = null)
 {
     Validate::isString($container, 'container');
     Validate::isString($blob, 'blob');
     $method = Resources::HTTP_GET;
     $headers = array();
     $postParams = array();
     $queryParams = array();
     $path = $this->_createPath($container, $blob);
     $statusCode = array(Resources::STATUS_OK, Resources::STATUS_PARTIAL_CONTENT);
     if (is_null($options)) {
         $options = new GetBlobOptions();
     }
     $getMD5 = $options->getComputeRangeMD5();
     $headers = $this->addOptionalAccessConditionHeader($headers, $options->getAccessCondition());
     $headers = $this->_addOptionalRangeHeader($headers, $options->getRangeStart(), $options->getRangeEnd());
     $this->addOptionalHeader($headers, Resources::X_MS_LEASE_ID, $options->getLeaseId());
     $this->addOptionalHeader($headers, Resources::X_MS_RANGE_GET_CONTENT_MD5, $getMD5 ? 'true' : null);
     $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout());
     $this->addOptionalQueryParam($queryParams, Resources::QP_SNAPSHOT, $options->getSnapshot());
     $response = $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode);
     $metadata = $this->getMetadataArray(HttpFormatter::formatHeaders($response->getHeaders()));
     return GetBlobResult::create(HttpFormatter::formatHeaders($response->getHeaders()), $response->getBody(), $metadata);
 }
 /**
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::createBlobSnapshot
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::createPageBlob
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::deleteBlob
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::getBlob
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::setBlobMetadata
  */
 private function getBlobWorker($options, $container)
 {
     $blob = BlobServiceFunctionalTestData::getInterestingBlobName($container);
     // Make sure there is something to test
     $dataSize = 512;
     $this->restProxy->createPageBlob($container, $blob, $dataSize);
     $metadata = BlobServiceFunctionalTestData::getNiceMetadata();
     $sbmd = $this->restProxy->setBlobMetadata($container, $blob, $metadata);
     $snapshot = $this->restProxy->createBlobSnapshot($container, $blob);
     $this->restProxy->createBlobSnapshot($container, $blob);
     if (!is_null($options)) {
         BlobServiceFunctionalTestData::fixETagAccessCondition($options->getAccessCondition(), $sbmd->getETag());
         $options->setSnapshot(is_null($options->getSnapshot()) ? null : $snapshot->getSnapshot());
     }
     try {
         $res = is_null($options) ? $this->restProxy->getBlob($container, $blob) : $this->restProxy->getBlob($container, $blob, $options);
         if (is_null($options)) {
             $options = new GetBlobOptions();
         }
         if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) {
             $this->assertTrue(false, 'Expect negative timeouts in $options to throw');
         }
         if (!BlobServiceFunctionalTestData::passTemporalAccessCondition($options->getAccessCondition())) {
             $this->assertTrue(false, 'Expect failing temporal access condition should throw');
         }
         if (!BlobServiceFunctionalTestData::passTemporalAccessCondition($options->getAccessCondition())) {
             $this->assertTrue(false, 'Expect failing etag access condition to throw');
         }
         if ($options->getComputeRangeMD5() && is_null($options->getRangeStart())) {
             $this->assertTrue(false, 'Expect compute range MD5 to fail if range not set');
         }
         $this->verifyGetBlobWorker($res, $options, $dataSize, $metadata);
     } catch (ServiceException $e) {
         if (!is_null($options->getAccessCondition()) && !$this->hasSecureEndpoint() && $e->getCode() == TestResources::STATUS_FORBIDDEN) {
             // Proxies can eat the access condition headers of
             // unsecured (http) requests, which causes the authentication
             // to fail, with a 403:Forbidden. There is nothing much that
             // can be done about this, other than ignore it.
         } else {
             if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) {
                 $this->assertEquals(TestResources::STATUS_INTERNAL_SERVER_ERROR, $e->getCode(), 'bad timeout: getCode');
             } else {
                 if (!BlobServiceFunctionalTestData::passTemporalAccessCondition($options->getAccessCondition())) {
                     if ($options->getAccessCondition()->getHeader() == Resources::IF_MODIFIED_SINCE) {
                         $this->assertEquals(TestResources::STATUS_NOT_MODIFIED, $e->getCode(), 'bad temporal access condition IF_MODIFIED_SINCE: getCode');
                     } else {
                         $this->assertEquals(TestResources::STATUS_PRECONDITION_FAILED, $e->getCode(), 'bad temporal access condition IF_UNMODIFIED_SINCE: getCode');
                     }
                 } else {
                     if (!BlobServiceFunctionalTestData::passETagAccessCondition($options->getAccessCondition())) {
                         $this->assertEquals(TestResources::STATUS_PRECONDITION_FAILED, $e->getCode(), 'bad etag access condition: getCode');
                     } else {
                         if ($options->getComputeRangeMD5() && is_null($options->getRangeStart())) {
                             $this->assertEquals(TestResources::STATUS_BAD_REQUEST, $e->getCode(), 'Expect compute range MD5 to fail when range not set: getCode');
                         } else {
                             throw $e;
                         }
                     }
                 }
             }
         }
     }
     // Clean up.
     $this->restProxy->deleteBlob($container, $blob);
 }
 /**
  * @covers MicrosoftAzure\Storage\Blob\Models\GetBlobOptions::getComputeRangeMD5
  */
 public function testGetComputeRangeMD5()
 {
     // Setup
     $options = new GetBlobOptions();
     $expected = true;
     $options->setComputeRangeMD5($expected);
     // Test
     $actual = $options->getComputeRangeMD5();
     // Assert
     $this->assertEquals($expected, $actual);
 }