Getting Started

Back to Getting Started.

Blob storage

Blob Storage stores sets of binary data. Blob storage offers the following three resources: the storage account, containers, and blobs. Within your storage account, containers provide a way to organize sets of blobs within your storage account.

Blob Storage is offered by Windows Azure as a REST API which is wrapped by the Windows Azure SDK for PHP in order to provide a native PHP interface to the storage account.

API examples

This topic lists some examples of using the PHPAzure SDK. Other features are available in the download package, as well as a detailed API documentation of those features.

Creating a storage container

Using the following code, a blob storage container can be created on development storage:
/** Microsoft_WindowsAzure_Storage_Blob */
require_once 'Microsoft/WindowsAzure/Storage/Blob.php';

$storageClient = new Microsoft_WindowsAzure_Storage_Blob();
$result = $storageClient->createContainer('testcontainer');

echo 'Container name is: ' . $result->Name;

Deleting a storage container

Using the following code, a blob storage container can be removed from development storage:
/** Microsoft_WindowsAzure_Storage_Blob */
require_once 'Microsoft/WindowsAzure/Storage/Blob.php';

$storageClient = new Microsoft_WindowsAzure_Storage_Blob();
$storageClient->deleteContainer('testcontainer');

Storing a blob

Using the following code, a blob can be uploaded to a blob storage container on development storage. Note that the container has already been created before.
/** Microsoft_WindowsAzure_Storage_Blob */
require_once 'Microsoft/WindowsAzure/Storage/Blob.php';

$storageClient = new Microsoft_WindowsAzure_Storage_Blob();

// upload /home/maarten/example.txt to Windows Azure
$result = $storageClient->putBlob('testcontainer', 'example.txt', '/home/maarten/example.txt');

echo 'Blob name is: ' . $result->Name;

Copying a blob

Using the following code, a blob can be copied from inside the storage account. The advantage of using this method is that the copy operation occurs in the Azure cloud and does not involve downloading the blob. Note that the container has already been created before.
/** Microsoft_WindowsAzure_Storage_Blob */
require_once 'Microsoft/WindowsAzure/Storage/Blob.php';

$storageClient = new Microsoft_WindowsAzure_Storage_Blob();

// copy example.txt to example2.txt
$result = $storageClient->copyBlob('testcontainer', 'example.txt', 'testcontainer', 'example2.txt');

echo 'Copied blob name is: ' . $result->Name;

Downloading a blob

Using the following code, a blob can be downloaded from a blob storage container on development storage. Note that the container has already been created before and a blob has been uploaded.
/** Microsoft_WindowsAzure_Storage_Blob */
require_once 'Microsoft/WindowsAzure/Storage/Blob.php';

$storageClient = new Microsoft_WindowsAzure_Storage_Blob();

// download file to /home/maarten/example.txt
$storageClient->getBlob('testcontainer', 'example.txt', '/home/maarten/example.txt');

Making a blob publicly available

By default, blob storage containers on Windows Azure are protected from public viewing. If any user on the Internet should have access to a blob container, its ACL can be set to public. Note that this applies to a complete container and not to a single blob!

Using the following code, blob storage container ACL can be set on development storage. Note that the container has already been created before.
/** Microsoft_WindowsAzure_Storage_Blob */
require_once 'Microsoft/WindowsAzure/Storage/Blob.php';

$storageClient = new Microsoft_WindowsAzure_Storage_Blob();

// make container publicly available (enumerate all blobs and read blob data)
$storageClient->setContainerAcl('testcontainer', Microsoft_WindowsAzure_Storage_Blob::ACL_PUBLIC_CONTAINER);

Root container

Windows Azure Blob Storage provides support to work with a "root container". This means that a blob can be stored in the root of your storage account, i.e. http://myaccount.blob.core.windows.net/somefile.txt.

In order to work with the root container, it should first be created using the createContainer() method, naming the container $root. All other operations on the root container should be issued with the container name set to $root.

Last edited Jun 10, 2010 at 7:14 AM by maartenba, version 12

Comments

No comments yet.