Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Commit

Permalink
Added useTransactionalMD5 option when uploading blockblob, pageblob a…
Browse files Browse the repository at this point in the history
…nd file; Fixed a bug about CopyBlobFromURLOptions not found.
  • Loading branch information
XiaoningLiu committed Jan 5, 2018
1 parent 618c9b2 commit 01d9644
Show file tree
Hide file tree
Showing 23 changed files with 368 additions and 95 deletions.
2 changes: 2 additions & 0 deletions BreakingChanges.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ All

Blob
* Removed `dataSerializer` parameter from `BlobRextProxy` constructor.
* Option parameter type of `BlobRestProxy::CreateBlockBlob` and `BlobRestProxy::CreatePageBlobFromContent` changed and added `setUseTransactionalMD5` method.

Table
* Removed `dataSerializer` parameter from `TableRextProxy` constructor.
Expand All @@ -25,6 +26,7 @@ Queue

File
* Removed `dataSerializer` parameter from `FileRextProxy` constructor.
* Option parameter type of `FileRestProxy::CreateFileFromContent` changed and added `setUseTransactionalMD5` method.

Tracking Breaking changes in 0.19.0

Expand Down
5 changes: 4 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
**Note: This changelog is deprecated starting with version 1.0.0, please refer to the ChangeLog.md in each package for future change logs.**

2017.12 - version 1.0.0
2018.01 - version 1.0.0

All
* Split azure-storage composer package into azure-storage-blob, azure-storage-table, azure-storage-queue, azure-storage-file and azure-storage-common packages.
Expand All @@ -16,7 +16,9 @@ All
Blob
* Created `BlobSharedAccessSignatureHelper` and moved method `SharedAccessSignatureHelper::generateBlobServiceSharedAccessSignatureToken()` into `BlobSharedAccessSignatureHelper`.
* Added static builder methods `createBlobService` and `createContainerAnonymousAccess` into `BlobRestProxy`.
* Added `setUseTransactionalMD5` method for options of `BlobRestProxy::CreateBlockBlob` and `BlobRestProxy::CreatePageBlobFromContent`. Default false, enabling transactional MD5 validation will take more cpu and memory resources.
* Removed `dataSerializer` parameter from `BlobRextProxy` constructor.
* Fixed a bug that CopyBlobFromURLOptions not found.

Table
* Created `TableSharedAccessSignatureHelper` and moved method `SharedAccessSignatureHelper::generateTableServiceSharedAccessSignatureToken()` into `TableSharedAccessSignatureHelper`.
Expand All @@ -32,6 +34,7 @@ Queue
File
* Created `FileSharedAccessSignatureHelper` and moved method `SharedAccessSignatureHelper::generateFileServiceSharedAccessSignatureToken()` into `FileSharedAccessSignatureHelper`.
* Added static builder methods `createFileService` into `FileRestProxy`.
* Added `setUseTransactionalMD5` method for option of `FileRestProxy::CreateFileFromContent`. Default false, enabling transactional MD5 validation will take more cpu and memory resources.
* Removed `dataSerializer` parameter from `FileRextProxy` constructor.

2017.09 - version 0.19.1
Expand Down
1 change: 1 addition & 0 deletions azure-storage-blob/BreakingChanges.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Tracking Breaking changes in 1.0.0

* Removed `dataSerializer` parameter from `BlobRextProxy` constructor.
* Option parameter type of `BlobRestProxy::CreateBlockBlob` and `BlobRestProxy::CreatePageBlobFromContent` changed and added `setUseTransactionalMD5` method.
* Deprecated PHP 5.5 support.
4 changes: 3 additions & 1 deletion azure-storage-blob/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
2017.12 - version 1.0.0
2018.01 - version 1.0.0

* Created `BlobSharedAccessSignatureHelper` and moved method `SharedAccessSignatureHelper::generateBlobServiceSharedAccessSignatureToken()` into `BlobSharedAccessSignatureHelper`.
* Added static builder methods `createBlobService` and `createContainerAnonymousAccess` into `BlobRestProxy`.
* Removed `dataSerializer` parameter from `BlobRextProxy` constructor.
* Added `setUseTransactionalMD5` method for options of `BlobRestProxy::CreateBlockBlob` and `BlobRestProxy::CreatePageBlobFromContent`. Default false, enabling transactional MD5 validation will take more cpu and memory resources.
* Fixed a bug that CopyBlobFromURLOptions not found.
* Deprecated PHP 5.5 support.
75 changes: 51 additions & 24 deletions azure-storage-blob/src/Blob/BlobRestProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use MicrosoftAzure\Storage\Blob\Models\BlockList;
use MicrosoftAzure\Storage\Blob\Models\BreakLeaseResult;
use MicrosoftAzure\Storage\Blob\Models\CommitBlobBlocksOptions;
use MicrosoftAzure\Storage\Blob\Models\CopyBlobFromURLOptions;
use MicrosoftAzure\Storage\Blob\Models\CopyBlobOptions;
use MicrosoftAzure\Storage\Blob\Models\CopyBlobResult;
use MicrosoftAzure\Storage\Blob\Models\CreateBlobBlockOptions;
Expand Down Expand Up @@ -1644,7 +1645,7 @@ public function createAppendBlobAsync(
* @param string $container The name of the container.
* @param string $blob The name of the blob.
* @param string|resource|StreamInterface $content The content of the blob.
* @param Models\CreateBlobOptions $options The optional parameters.
* @param Models\CreateBlockBlobOptions $options The optional parameters.
*
* @return Models\PutBlobResult
*
Expand All @@ -1654,7 +1655,7 @@ public function createBlockBlob(
$container,
$blob,
$content,
Models\CreateBlobOptions $options = null
Models\CreateBlockBlobOptions $options = null
) {
return $this->createBlockBlobAsync(
$container,
Expand All @@ -1677,7 +1678,7 @@ public function createBlockBlob(
* @param string $container The name of the container.
* @param string $blob The name of the blob.
* @param string|resource|StreamInterface $content The content of the blob.
* @param Models\CreateBlobOptions $options The optional parameters.
* @param Models\CreateBlockBlobOptions $options The optional parameters.
*
* @return \GuzzleHttp\Promise\PromiseInterface
*
Expand All @@ -1687,7 +1688,7 @@ public function createBlockBlobAsync(
$container,
$blob,
$content,
Models\CreateBlobOptions $options = null
Models\CreateBlockBlobOptions $options = null
) {
$body = Psr7\stream_for($content);

Expand Down Expand Up @@ -1725,7 +1726,8 @@ public function createBlockBlobAsync(
* @param string $blob The name of the blob.
* @param int $length The length of the blob.
* @param string|resource|StreamInterface $content The content of the blob.
* @param Models\CreateBlobOptions $options The optional parameters.
* @param Models\CreatePageBlobFromContentOptions
* $options The optional parameters.
*
* @return Models\GetBlobPropertiesResult
*
Expand All @@ -1736,7 +1738,7 @@ public function createPageBlobFromContent(
$blob,
$length,
$content,
Models\CreateBlobOptions $options = null
Models\CreatePageBlobFromContentOptions $options = null
) {
return $this->createPageBlobFromContentAsync(
$container,
Expand All @@ -1755,7 +1757,8 @@ public function createPageBlobFromContent(
* @param string $blob The name of the blob.
* @param int $length The length of the blob.
* @param string|resource|StreamInterface $content The content of the blob.
* @param Models\CreateBlobOptions $options The optional parameters.
* @param Models\CreatePageBlobFromContentOptions
* $options The optional parameters.
*
* @return \GuzzleHttp\Promise\PromiseInterface
*
Expand All @@ -1766,13 +1769,13 @@ public function createPageBlobFromContentAsync(
$blob,
$length,
$content,
Models\CreateBlobOptions $options = null
Models\CreatePageBlobFromContentOptions $options = null
) {
$body = Psr7\stream_for($content);
$self = $this;

if (is_null($options)) {
$options = new CreateBlobOptions();
$options = new Models\CreatePageBlobFromContentOptions();
}

$createBlobPromise = $this->createPageBlobAsync(
Expand Down Expand Up @@ -1900,19 +1903,19 @@ function ($response) {
* This method creates the blob blocks. This method will send the request
* concurrently for better performance.
*
* @param string $container Name of the container
* @param string $blob Name of the blob
* @param StreamInterface $content Content's stream
* @param Models\CreateBlobOptions $options Array that contains
* all the option
* @param string $container Name of the container
* @param string $blob Name of the blob
* @param StreamInterface $content Content's stream
* @param Models\CreateBlockBlobOptions $options Array that contains
* all the option
*
* @return \GuzzleHttp\Promise\PromiseInterface
*/
protected function createBlockBlobByMultipleUploadAsync(
$container,
$blob,
$content,
Models\CreateBlobOptions $options = null
Models\CreateBlockBlobOptions $options = null
) {
Validate::canCastAsString($container, 'container');
Validate::canCastAsString($blob, 'blob');
Expand All @@ -1925,16 +1928,17 @@ protected function createBlockBlobByMultipleUploadAsync(
}

if (is_null($options)) {
$options = new CreateBlobOptions();
$options = new Models\CreateBlockBlobOptions();
}

$createBlobBlockOptions = CreateBlobBlockOptions::create($options);
$selfInstance = $this;

$method = Resources::HTTP_PUT;
$headers = $this->createBlobBlockHeader($createBlobBlockOptions);
$postParams = array();
$path = $this->createPath($container, $blob);
$method = Resources::HTTP_PUT;
$headers = $this->createBlobBlockHeader($createBlobBlockOptions);
$postParams = array();
$path = $this->createPath($container, $blob);
$useTransactionalMD5 = $options->getUseTransactionalMD5();

$blockIds = array();
//Determine the block size according to the content and threshold.
Expand All @@ -1951,6 +1955,7 @@ protected function createBlockBlobByMultipleUploadAsync(
$headers,
$postParams,
$path,
$useTransactionalMD5,
&$counter,
$selfInstance
) {
Expand All @@ -1964,6 +1969,16 @@ protected function createBlockBlobByMultipleUploadAsync(
if ($size == 0) {
return null;
}

if ($useTransactionalMD5) {
$contentMD5 = base64_encode(md5($blockContent, true));
$selfInstance->addOptionalHeader(
$headers,
Resources::CONTENT_MD5,
$contentMD5
);
}

//add the id to array.
array_push($blockIds, new Block($blockId, 'Uncommitted'));
$queryParams = $selfInstance->createBlobBlockQueryParams(
Expand Down Expand Up @@ -2022,16 +2037,17 @@ function ($value) use (
* @param string $container Name of the container
* @param string $blob Name of the blob
* @param StreamInterface $content Content's stream
* @param Models\CreateBlobOptions $options Array that contains
* all the option
* @param Models\CreatePageBlobFromContentOptions
* $options Array that contains
* all the option
*
* @return \GuzzleHttp\Promise\PromiseInterface
*/
private function uploadPageBlobAsync(
$container,
$blob,
$content,
Models\CreateBlobOptions $options = null
Models\CreatePageBlobFromContentOptions $options = null
) {
Validate::canCastAsString($container, 'container');
Validate::notNullOrEmpty($container, 'container');
Expand All @@ -2040,13 +2056,14 @@ private function uploadPageBlobAsync(
Validate::notNullOrEmpty($blob, 'blob');

if (is_null($options)) {
$options = new CreateBlobOptions();
$options = new Models\CreatePageBlobFromContentOptions();
}

$method = Resources::HTTP_PUT;
$postParams = array();
$queryParams = array();
$path = $this->createPath($container, $blob);
$useTransactionalMD5 = $options->getUseTransactionalMD5();

$this->addOptionalQueryParam($queryParams, Resources::QP_COMP, 'page');
$this->addOptionalQueryParam(
Expand All @@ -2067,6 +2084,7 @@ private function uploadPageBlobAsync(
$postParams,
$queryParams,
$path,
$useTransactionalMD5,
&$start,
&$end,
$options
Expand Down Expand Up @@ -2107,6 +2125,15 @@ private function uploadPageBlobAsync(
PageWriteOption::UPDATE_OPTION
);

if ($useTransactionalMD5) {
$contentMD5 = base64_encode(md5($pageContent, true));
$this->addOptionalHeader(
$headers,
Resources::CONTENT_MD5,
$contentMD5
);
}

//return the array of requests.
return $this->createRequest(
$method,
Expand Down
30 changes: 16 additions & 14 deletions azure-storage-blob/src/Blob/Internal/IBlob.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,10 +488,10 @@ public function createAppendBlobAsync(
* existing blob is overwritten with the content of the new blob. To perform a
* partial update of the content of a block blob, use the createBlockList method.
*
* @param string $container name of the container
* @param string $blob name of the blob
* @param string $content content of the blob
* @param BlobModels\CreateBlobOptions $options optional parameters
* @param string $container name of the container
* @param string $blob name of the blob
* @param string $content content of the blob
* @param BlobModels\CreateBlockBlobOptions $options optional parameters
*
* @return BlobModels\CopyBlobResult
*
Expand All @@ -501,7 +501,7 @@ public function createBlockBlob(
$container,
$blob,
$content,
BlobModels\CreateBlobOptions $options = null
BlobModels\CreateBlockBlobOptions $options = null
);

/**
Expand All @@ -514,10 +514,10 @@ public function createBlockBlob(
* partial update of the content of a block blob, use the createBlockList
* method.
*
* @param string $container The name of the container.
* @param string $blob The name of the blob.
* @param string|resource|StreamInterface $content The content of the blob.
* @param BlobModels\CreateBlobOptions $options The optional parameters.
* @param string $container The name of the container.
* @param string $blob The name of the blob.
* @param string|resource|StreamInterface $content The content of the blob.
* @param BlobModels\CreateBlockBlobOptions $options The optional parameters.
*
* @return \GuzzleHttp\Promise\PromiseInterface
*
Expand All @@ -527,7 +527,7 @@ public function createBlockBlobAsync(
$container,
$blob,
$content,
BlobModels\CreateBlobOptions $options = null
BlobModels\CreateBlockBlobOptions $options = null
);

/**
Expand All @@ -537,7 +537,8 @@ public function createBlockBlobAsync(
* @param string $blob The name of the blob.
* @param int $length The length of the blob.
* @param string|resource|StreamInterface $content The content of the blob.
* @param BlobModels\CreateBlobOptions $options The optional parameters.
* @param BlobModels\CreatePageBlobFromContentOptions
* $options The optional parameters.
*
* @return BlobModels\GetBlobPropertiesResult
*
Expand All @@ -548,7 +549,7 @@ public function createPageBlobFromContent(
$blob,
$length,
$content,
BlobModels\CreateBlobOptions $options = null
BlobModels\CreatePageBlobFromContentOptions $options = null
);

/**
Expand All @@ -559,7 +560,8 @@ public function createPageBlobFromContent(
* @param string $blob The name of the blob.
* @param int $length The length of the blob.
* @param string|resource|StreamInterface $content The content of the blob.
* @param BlobModels\CreateBlobOptions $options The optional parameters.
* @param BlobModels\CreatePageBlobFromContentOptions
* $options The optional parameters.
*
* @return \GuzzleHttp\Promise\PromiseInterface
*
Expand All @@ -570,7 +572,7 @@ public function createPageBlobFromContentAsync(
$blob,
$length,
$content,
BlobModels\CreateBlobOptions $options = null
BlobModels\CreatePageBlobFromContentOptions $options = null
);

/**
Expand Down
Loading

0 comments on commit 01d9644

Please sign in to comment.