function InitializeStorage() { if (USE_DEV_EMULATOR) { //Connect to the Storage Emulator $tableClient = new Microsoft_WindowsAzure_Storage_Table(); $blobClient = new Microsoft_WindowsAzure_Storage_Blob(); $queueClient = new Microsoft_WindowsAzure_Storage_Queue(); } else { //Connect to Azure storage $tableClient = new Microsoft_WindowsAzure_Storage_Table(AZURE_TABLES_URL, AZURE_STORAGE_ACCOUNT, AZURE_STORAGE_KEY); $blobClient = new Microsoft_WindowsAzure_Storage_Blob(AZURE_BLOBS_URL, AZURE_STORAGE_ACCOUNT, AZURE_STORAGE_KEY); $queueClient = new Microsoft_WindowsAzure_Storage_Table(AZURE_QUEUES_URL, AZURE_STORAGE_ACCOUNT, AZURE_STORAGE_KEY); } //Create a table to store GuestBook Entries if it doesn't exist if (!$tableClient->tableExists(GB_TABLE_NAME)) { $result = $tableClient->createTable(GB_TABLE_NAME); } //Validate the blob container name if ($blobClient->isValidContainerName(GB_BLOB_CONTAINER)) { if (!$blobClient->containerExists(GB_BLOB_CONTAINER)) { //create it if it doesn't exist $result = $blobClient->createContainer(GB_BLOB_CONTAINER); //Make it public $blobClient->setContainerAcl(GB_BLOB_CONTAINER, Microsoft_WindowsAzure_Storage_Blob::ACL_PUBLIC); $blobClient->registerStreamWrapper(); } } //Create a queue to send thumbnail jobs to a worker process if it doesn't exist $queue = $queueClient->createQueueIfNotExists(GB_QUEUE_NAME); return array($tableClient, $blobClient, $queueClient); }
/** * @see FileBackend::secure() */ function doSecureInternal($container, $dir, array $params) { $status = Status::newGood(); try { if ($this->storageClient->containerExists($container)) { if ($params['noAccess'] == true) { $this->storageClient->setContainerAcl($container, Microsoft_WindowsAzure_Storage_Blob::ACL_PRIVATE); } } } catch (Exception $e) { $status->fatal('directorycreateerror', $container); return $status; } return $status; }
/** * Creates bucket * * @param string $container_id * @param string $error * @return boolean */ function create_container(&$container_id, &$error) { if (!$this->_init($error)) { return false; } try { $containers = $this->_client->listContainers(); } catch (Exception $exception) { $error = sprintf('Unable to list containers (%s).', $exception->getMessage()); return false; } if (in_array($this->_config['container'], (array) $containers)) { $error = sprintf('Container already exists: %s.', $this->_config['container']); return false; } try { $this->_client->createContainer($this->_config['container']); $this->_client->setContainerAcl($this->_config['container'], Microsoft_WindowsAzure_Storage_Blob::ACL_PUBLIC_BLOB); } catch (Exception $exception) { $error = sprintf('Unable to create container: %s (%s)', $this->_config['container'], $exception->getMessage()); return false; } return true; }
/** * @see FileBackend::prepare() */ function doPrepareInternal( $container, $dir, array $params ) { $status = Status::newGood(); list( $c, $dir ) = $this->resolveStoragePath( $params['dir'] ); if ( $dir === null ) { $status->fatal( 'backend-fail-invalidpath', $params['dir'] ); return $status; // invalid storage path } try { $this->storageClient->createContainerIfNotExists( $c ); // TODO: must this be set anytime prepare is called? $this->storageClient->setContainerAcl( $c, Microsoft_WindowsAzure_Storage_Blob::ACL_PUBLIC ); // TODO: check if readable and writeable //$container = $this->storageClient->getContainer( $c ); //$status->fatal( 'directoryreadonlyerror', $params['dir'] ); //$status->fatal( 'directorynotreadableerror', $params['dir'] ); } catch (Exception $e ) { $status->fatal( 'directorycreateerror', $params['dir'] ); return $status; } return $status; }
<?php require_once 'Microsoft/WindowsAzure/Storage/Blob.php'; $storageClient = new Microsoft_WindowsAzure_Storage_Blob(); // rende il container pubblicamente accessibile $storageClient->setContainerAcl('testcontainer', Microsoft_WindowsAzure_Storage_Blob::ACL_PUBLIC_CONTAINER);
// Setup the connection if (DEV) { // Connect to local development storage $table = new Microsoft_WindowsAzure_Storage_Table(); $blob = new Microsoft_WindowsAzure_Storage_Blob(); } else { // Connect to Windows Azure Storage in the cloud $table = new Microsoft_WindowsAzure_Storage_Table('table.core.windows.net', STORAGE_ACCOUNT, STORAGE_KEY); $blob = new Microsoft_WindowsAzure_Storage_Blob('blob.core.windows.net', STORAGE_ACCOUNT, STORAGE_KEY); } // Ensure the table exists $table->createTableIfNotExists(TABLE_GUESTBOOK); // Ensure the blob container exists $blob->createcontainerIfNotExists(BLOB_GUESTBOOK); // Set ACL $blob->setContainerAcl(BLOB_GUESTBOOK, Microsoft_WindowsAzure_Storage_Blob::ACL_PUBLIC_CONTAINER); // If the user submitted something put it into the table storage // NOTE: Inputs are not cleaned for example purposes if (isset($_POST['NameTextBox']) && isset($_POST['MessageTextBox'])) { $g = new GuestBookEntry(); $image = $blob->putBlob(BLOB_GUESTBOOK, $_FILES['Image']['name'], $_FILES['Image']['tmp_name']); $g->GuestName = $_POST['NameTextBox']; $g->Message = $_POST['MessageTextBox']; $g->ImageUrl = $image->Url; $table->insertEntity(TABLE_GUESTBOOK, $g); } // User wishes to delete something if (isset($_GET['Delete']) && isset($_GET['key'])) { $g = $table->retrieveEntityById(TABLE_GUESTBOOK, $_GET['Delete'], $_GET['key']); $table->deleteEntity(TABLE_GUESTBOOK, $g); header("Location: index.php");