Modified ChangeLog.md and add samples.
This commit is contained in:
Родитель
00b537e21b
Коммит
cfa89bd93b
|
@ -1,5 +1,10 @@
|
|||
2017.06 - version 0.16.0
|
||||
|
||||
All
|
||||
* Renamed and moved `MicrosoftAzure\Storage\Blob\Models\PageRange` to `MicrosoftAzure\Storage\Common\Models\Range`.
|
||||
* Added support for Service Shared Access Signature.
|
||||
* With File service feature parity to 2015-04-05 and Service Shared Access Signature support in this release, the SDK now have full parity for Blob, Table, Queue and File services to REST API version 2015-04-05.
|
||||
|
||||
Table
|
||||
* Created new types for the following APIs to support specifying accepted content type of response payload. Payload is now by default `application/json;odata=minimalmetadata`.
|
||||
- `MicrosoftAzure\Storage\Table\TableRestProxy::createTable` & `MicrosoftAzure\Storage\Table\TableRestProxy::createTableAsync` now uses `MicrosoftAzure\Storage\Table\Models\TableServiceCreateOptions`.
|
||||
|
@ -12,6 +17,9 @@ Table
|
|||
Queue
|
||||
* Renamed `MicrosoftAzure\Storage\Queue\Models\MicrosoftAzureQueueMessage` to `MicrosoftAzure\Storage\Queue\Models\QueueMessage`
|
||||
|
||||
File
|
||||
* Added full support for File service, with parity to REST API 2015-04-05.
|
||||
|
||||
2017.04 - version 0.15.0
|
||||
|
||||
All
|
||||
|
|
|
@ -32,9 +32,9 @@ use MicrosoftAzure\Storage\Blob\Models\CreateBlobOptions;
|
|||
use MicrosoftAzure\Storage\Blob\Models\GetBlobOptions;
|
||||
use MicrosoftAzure\Storage\Blob\Models\ContainerAcl;
|
||||
use MicrosoftAzure\Storage\Blob\Models\SetBlobPropertiesOptions;
|
||||
use MicrosoftAzure\Storage\Blob\Models\PageRange;
|
||||
use MicrosoftAzure\Storage\Blob\Models\ListPageBlobRangesOptions;
|
||||
use MicrosoftAzure\Storage\Common\ServicesBuilder;
|
||||
use MicrosoftAzure\Storage\Common\Models\Range;
|
||||
use MicrosoftAzure\Storage\Common\Models\Logging;
|
||||
use MicrosoftAzure\Storage\Common\Models\Metrics;
|
||||
use MicrosoftAzure\Storage\Common\Models\RetentionPolicy;
|
||||
|
@ -43,12 +43,10 @@ use MicrosoftAzure\Storage\Common\Exceptions\ServiceException;
|
|||
use MicrosoftAzure\Storage\Common\Exceptions\InvalidArgumentTypeException;
|
||||
|
||||
$connectionString = 'DefaultEndpointsProtocol=https;AccountName=<yourAccount>;AccountKey=<yourKey>';
|
||||
$connectionString = 'DefaultEndpointsProtocol=https;AccountName=phput;AccountKey=LCtFmRVvbWj9C+U2GPF4oLXWZRABJgRn8pS6hBxeoFYDQNPk/2teTxqAJO8GmYHoNPKU+bIWtBxTN42BorMlXQ==';
|
||||
|
||||
$blobClient = ServicesBuilder::getInstance()->createBlobService($connectionString);
|
||||
|
||||
// Get and Set Blob Service Properties
|
||||
blobServiceProperties($blobClient);
|
||||
setBlobServiceProperties($blobClient);
|
||||
|
||||
// To create a container call createContainer.
|
||||
createContainerSample($blobClient);
|
||||
|
@ -111,7 +109,7 @@ try {
|
|||
echo $code.": ".$error_message.PHP_EOL;
|
||||
}
|
||||
|
||||
function blobServiceProperties($blobClient)
|
||||
function setBlobServiceProperties($blobClient)
|
||||
{
|
||||
// Get blob service properties
|
||||
echo "Get Blob Service properties" . PHP_EOL;
|
||||
|
@ -447,13 +445,13 @@ function pageBlobOperations($blobClient)
|
|||
$blobClient->createBlobPages(
|
||||
$containerName,
|
||||
$blobName,
|
||||
new PageRange(0, 511),
|
||||
new Range(0, 511),
|
||||
generateRandomString(512)
|
||||
);
|
||||
$blobClient->createBlobPages(
|
||||
$containerName,
|
||||
$blobName,
|
||||
new PageRange(512, 1023),
|
||||
new Range(512, 1023),
|
||||
generateRandomString(512)
|
||||
);
|
||||
# List page blob ranges
|
||||
|
@ -467,11 +465,11 @@ function pageBlobOperations($blobClient)
|
|||
$listPageBlobRangesOptions
|
||||
);
|
||||
|
||||
foreach ($listPageBlobRangesResult->getPageRanges() as $pageRange) {
|
||||
echo "Range:".$pageRange->getStart()."-".$pageRange->getEnd().PHP_EOL;
|
||||
foreach ($listPageBlobRangesResult->getRanges() as $range) {
|
||||
echo "Range:".$range->getStart()."-".$range->getEnd().PHP_EOL;
|
||||
$getBlobOptions = new GetBlobOptions();
|
||||
$getBlobOptions->setRangeStart($pageRange->getStart());
|
||||
$getBlobOptions->setRangeEnd($pageRange->getEnd());
|
||||
$getBlobOptions->setRangeStart($range->getStart());
|
||||
$getBlobOptions->setRangeEnd($range->getEnd());
|
||||
$getBlobResult = $blobClient->getBlob($containerName, $blobName, $getBlobOptions);
|
||||
file_put_contents("PageContent.txt", $getBlobResult->getContentStream());
|
||||
}
|
||||
|
|
|
@ -0,0 +1,385 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* LICENSE: The MIT License (the "License")
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* https://github.com/azure/azure-storage-php/LICENSE
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Samples
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2017 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
|
||||
namespace MicrosoftAzure\Storage\Samples;
|
||||
|
||||
require_once "../vendor/autoload.php";
|
||||
|
||||
use MicrosoftAzure\Storage\Common\ServicesBuilder;
|
||||
use MicrosoftAzure\Storage\Common\Models\Range;
|
||||
use MicrosoftAzure\Storage\Common\Models\Metrics;
|
||||
use MicrosoftAzure\Storage\Common\Models\RetentionPolicy;
|
||||
use MicrosoftAzure\Storage\Common\Models\ServiceProperties;
|
||||
use MicrosoftAzure\Storage\Common\Exceptions\ServiceException;
|
||||
use MicrosoftAzure\Storage\Common\Exceptions\InvalidArgumentTypeException;
|
||||
use MicrosoftAzure\Storage\File\Models\CreateShareOptions;
|
||||
use MicrosoftAzure\Storage\File\Models\ListSharesOptions;
|
||||
|
||||
$connectionString = 'DefaultEndpointsProtocol=https;AccountName=<yourAccount>;AccountKey=<yourKey>';
|
||||
$fileClient = ServicesBuilder::getInstance()->createFileService($connectionString);
|
||||
|
||||
//Operations for File service properties;
|
||||
setFileServiceProperties($fileClient);
|
||||
|
||||
//Create share
|
||||
createShare($fileClient);
|
||||
|
||||
//List share
|
||||
listShare($fileClient);
|
||||
|
||||
//Delete share
|
||||
deleteShare($fileClient);
|
||||
|
||||
//Create directory
|
||||
createDirectory($fileClient);
|
||||
|
||||
//Delete directory
|
||||
deleteDirectory($fileClient);
|
||||
|
||||
//Create file
|
||||
createFile($fileClient);
|
||||
|
||||
//Delete file
|
||||
deleteFile($fileClient);
|
||||
|
||||
//List directories and files
|
||||
listDirectoriesAndFiles($fileClient);
|
||||
|
||||
//Put file range
|
||||
putFileRanges($fileClient);
|
||||
|
||||
//Clear file range
|
||||
clearFileRanges($fileClient);
|
||||
|
||||
//List file range
|
||||
listFileRanges($fileClient);
|
||||
|
||||
//Copy file
|
||||
copyFile($fileClient);
|
||||
|
||||
//Clean up
|
||||
cleanUp($fileClient);
|
||||
|
||||
function setFileServiceProperties($fileClient)
|
||||
{
|
||||
$originalProperties = $fileClient->getServiceProperties();
|
||||
$retentionPolicy = new RetentionPolicy();
|
||||
$retentionPolicy->setEnabled(true);
|
||||
$retentionPolicy->setDays(10);
|
||||
|
||||
$metrics = new Metrics();
|
||||
$metrics->setRetentionPolicy($retentionPolicy);
|
||||
$metrics->setVersion('1.0');
|
||||
$metrics->setEnabled(true);
|
||||
$metrics->setIncludeAPIs(true);
|
||||
$serviceProperties = new ServiceProperties();
|
||||
$serviceProperties->setHourMetrics($metrics);
|
||||
$fileClient->setServiceProperties($serviceProperties);
|
||||
// revert back to original properties
|
||||
$fileClient->setServiceProperties($originalProperties->getValue());
|
||||
}
|
||||
|
||||
function createShare($fileClient)
|
||||
{
|
||||
// OPTIONAL: Set metadata.
|
||||
// Create share options object.
|
||||
$createShareOptions = new CreateShareOptions();
|
||||
|
||||
// Set share metadata
|
||||
$createShareOptions->addMetaData("key1", "value1");
|
||||
$createShareOptions->addMetaData("key2", "value2");
|
||||
|
||||
// Set quota of the share
|
||||
$createShareOptions->setQuota(1024);
|
||||
|
||||
$shareName = 'myshare' . generateRandomString();
|
||||
|
||||
try {
|
||||
// Create share.
|
||||
createShareWorker($fileClient, $shareName, $createShareOptions);
|
||||
} catch (ServiceException $e) {
|
||||
$code = $e->getCode();
|
||||
$error_message = $e->getMessage();
|
||||
echo $code . ": " . $error_message . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
function createShareWorker($fileClient, $name, $options = null)
|
||||
{
|
||||
$error_message = '';
|
||||
static $createdShares = array();
|
||||
try {
|
||||
// Create share.
|
||||
$fileClient->createShare($name, $options);
|
||||
} catch (ServiceException $e) {
|
||||
$code = $e->getCode();
|
||||
$error_message = $e->getMessage();
|
||||
echo $code . ": " . $error_message . PHP_EOL;
|
||||
}
|
||||
if ($error_message === '') {
|
||||
$createdShares[] = $name;
|
||||
return $createdShares;
|
||||
}
|
||||
}
|
||||
|
||||
function listShare($fileClient)
|
||||
{
|
||||
// OPTIONAL: set prefix.
|
||||
$listShareOptions = new ListSharesOptions();
|
||||
$listShareOptions->setPrefix('myshare');
|
||||
|
||||
$shareName = 'myshare' . generateRandomString();
|
||||
|
||||
try {
|
||||
// Create share.
|
||||
createShareWorker($fileClient, $shareName);
|
||||
// List share.
|
||||
return $fileClient->listShares($listShareOptions);
|
||||
} catch (ServiceException $e) {
|
||||
$code = $e->getCode();
|
||||
$error_message = $e->getMessage();
|
||||
echo $code . ": " . $error_message . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
function deleteShare($fileClient)
|
||||
{
|
||||
$shareName = 'myshare' . generateRandomString();
|
||||
|
||||
try {
|
||||
// Create share.
|
||||
createShareWorker($fileClient, $shareName);
|
||||
// Delete share.
|
||||
$fileClient->deleteShare($shareName);
|
||||
} catch (ServiceException $e) {
|
||||
$code = $e->getCode();
|
||||
$error_message = $e->getMessage();
|
||||
echo $code . ": " . $error_message . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
function createDirectory($fileClient)
|
||||
{
|
||||
$shareName = 'myshare' . generateRandomString();
|
||||
$directoryName = 'mydirectory' . generateRandomString();
|
||||
try {
|
||||
// Create share.
|
||||
createShareWorker($fileClient, $shareName);
|
||||
// Create directory.
|
||||
$fileClient->createDirectory($shareName, $directoryName);
|
||||
} catch (ServiceException $e) {
|
||||
$code = $e->getCode();
|
||||
$error_message = $e->getMessage();
|
||||
echo $code . ": " . $error_message . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
function deleteDirectory($fileClient)
|
||||
{
|
||||
$shareName = 'myshare' . generateRandomString();
|
||||
$directoryName = 'mydirectory' . generateRandomString();
|
||||
try {
|
||||
// Create share.
|
||||
createShareWorker($fileClient, $shareName);
|
||||
// Create directory.
|
||||
$fileClient->createDirectory($shareName, $directoryName);
|
||||
// Delete directory
|
||||
$fileClient->deleteDirectory($shareName, $directoryName);
|
||||
} catch (ServiceException $e) {
|
||||
$code = $e->getCode();
|
||||
$error_message = $e->getMessage();
|
||||
echo $code . ": " . $error_message . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
function createFile($fileClient)
|
||||
{
|
||||
$shareName = 'myshare' . generateRandomString();
|
||||
$fileName = 'myfile' . generateRandomString();
|
||||
try {
|
||||
// Create share.
|
||||
createShareWorker($fileClient, $shareName);
|
||||
// Create file.
|
||||
$fileClient->createFile($shareName, $fileName, 1024);
|
||||
} catch (ServiceException $e) {
|
||||
$code = $e->getCode();
|
||||
$error_message = $e->getMessage();
|
||||
echo $code . ": " . $error_message . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
function deleteFile($fileClient)
|
||||
{
|
||||
$shareName = 'myshare' . generateRandomString();
|
||||
$fileName = 'myfile' . generateRandomString();
|
||||
try {
|
||||
// Create share.
|
||||
createShareWorker($fileClient, $shareName);
|
||||
// Create file.
|
||||
$fileClient->createFile($shareName, $fileName, 1024);
|
||||
// Delete file
|
||||
$fileClient->deleteFile($shareName, $fileName);
|
||||
} catch (ServiceException $e) {
|
||||
$code = $e->getCode();
|
||||
$error_message = $e->getMessage();
|
||||
echo $code . ": " . $error_message . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
function listDirectoriesAndFiles($fileClient)
|
||||
{
|
||||
$shareName = 'myshare' . generateRandomString();
|
||||
$directoryName = 'mydirectory' . generateRandomString();
|
||||
$fileName = 'myfile' . generateRandomString();
|
||||
try {
|
||||
// Create share.
|
||||
createShareWorker($fileClient, $shareName);
|
||||
// Create file.
|
||||
$fileClient->createFile($shareName, $fileName, 1024);
|
||||
// Create directory.
|
||||
$fileClient->createDirectory($shareName, $directoryName);
|
||||
// List directories and files.
|
||||
return $fileClient->listDirectoriesAndFiles($shareName);
|
||||
} catch (ServiceException $e) {
|
||||
$code = $e->getCode();
|
||||
$error_message = $e->getMessage();
|
||||
echo $code . ": " . $error_message . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
function putFileRanges($fileClient)
|
||||
{
|
||||
$shareName = 'myshare' . generateRandomString();
|
||||
$fileName = 'myfile' . generateRandomString();
|
||||
$content = generateRandomString(512);
|
||||
$range = new Range(0, 511);
|
||||
try {
|
||||
// Create share.
|
||||
createShareWorker($fileClient, $shareName);
|
||||
// Create file.
|
||||
$fileClient->createFile($shareName, $fileName, 1024);
|
||||
// Put ranges.
|
||||
$fileClient->putFileRange($shareName, $fileName, $content, $range);
|
||||
} catch (ServiceException $e) {
|
||||
$code = $e->getCode();
|
||||
$error_message = $e->getMessage();
|
||||
echo $code . ": " . $error_message . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
function clearFileRanges($fileClient)
|
||||
{
|
||||
$shareName = 'myshare' . generateRandomString();
|
||||
$fileName = 'myfile' . generateRandomString();
|
||||
$content = generateRandomString(512);
|
||||
$range = new Range(0, 511);
|
||||
try {
|
||||
// Create share.
|
||||
createShareWorker($fileClient, $shareName);
|
||||
// Create file.
|
||||
$fileClient->createFile($shareName, $fileName, 1024);
|
||||
// Put ranges.
|
||||
$fileClient->putFileRange($shareName, $fileName, $content, $range);
|
||||
// Clear ranges.
|
||||
$fileClient->clearFileRange($shareName, $fileName, $range);
|
||||
} catch (ServiceException $e) {
|
||||
$code = $e->getCode();
|
||||
$error_message = $e->getMessage();
|
||||
echo $code . ": " . $error_message . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
function listFileRanges($fileClient)
|
||||
{
|
||||
$shareName = 'myshare' . generateRandomString();
|
||||
$fileName = 'myfile' . generateRandomString();
|
||||
$content = generateRandomString(512);
|
||||
$range = new Range(0, 511);
|
||||
try {
|
||||
// Create share.
|
||||
createShareWorker($fileClient, $shareName);
|
||||
// Create file.
|
||||
$fileClient->createFile($shareName, $fileName, 1024);
|
||||
// Put ranges.
|
||||
$fileClient->putFileRange($shareName, $fileName, $content, $range);
|
||||
// List ranges.
|
||||
return $fileClient->listFileRange($shareName, $fileName);
|
||||
} catch (ServiceException $e) {
|
||||
$code = $e->getCode();
|
||||
$error_message = $e->getMessage();
|
||||
echo $code . ": " . $error_message . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
function copyFile($fileClient)
|
||||
{
|
||||
$shareName = 'myshare' . generateRandomString();
|
||||
$srcfileName = 'myfile' . generateRandomString();
|
||||
$dstfileName = 'myfile' . generateRandomString();
|
||||
$content = generateRandomString(512);
|
||||
$range = new Range(0, 511);
|
||||
|
||||
$sourcePath = sprintf(
|
||||
'%s%s/%s',
|
||||
(string)$fileClient->getPsrPrimaryUri(),
|
||||
$shareName,
|
||||
$srcfileName
|
||||
);
|
||||
|
||||
try {
|
||||
// Create share.
|
||||
createShareWorker($fileClient, $shareName);
|
||||
// Create source file.
|
||||
$fileClient->createFile($shareName, $srcfileName, 1024);
|
||||
// Create destination file.
|
||||
$fileClient->createFile($shareName, $dstfileName, 1024);
|
||||
// Put ranges.
|
||||
$fileClient->putFileRange($shareName, $srcfileName, $content, $range);
|
||||
// Copy file.
|
||||
return $fileClient->copyFile($shareName, $dstfileName, $sourcePath);
|
||||
} catch (ServiceException $e) {
|
||||
$code = $e->getCode();
|
||||
$error_message = $e->getMessage();
|
||||
echo $code . ": " . $error_message . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
function cleanUp($fileClient)
|
||||
{
|
||||
//get created shares
|
||||
$createdShares =
|
||||
createShareWorker($fileClient, 'myshare' . generateRandomString());
|
||||
foreach ($createdShares as $share) {
|
||||
$fileClient->deleteShare($share);
|
||||
}
|
||||
}
|
||||
|
||||
function generateRandomString($length = 6)
|
||||
{
|
||||
$characters = 'abcdefghijklmnopqrstuvwxyz';
|
||||
$charactersLength = strlen($characters);
|
||||
$randomString = '';
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
||||
}
|
||||
return $randomString;
|
||||
}
|
Загрузка…
Ссылка в новой задаче