Esempio n. 1
0
 public function store($filename, $data, $options = array())
 {
     $retrying = isset($options['retry']);
     $options['container'] = Config::get('storage.container', 'default');
     try {
         $this->createBlockBlob($filename, $data, $options);
         return $this->getBlobService()->getUri() . '/' . $options['container'] . '/' . $filename;
     } catch (ServiceException $e) {
         //
         // Blob Container doesn't exists yet. Let's create it.
         //
         if ($e->getCode() == 404 && !$retrying) {
             $create_container_options = new CreateContainerOptions();
             $create_container_options->setPublicAccess(PublicAccessType::CONTAINER_AND_BLOBS);
             $create_container_options->addMetaData('created', date('U'));
             $this->getBlobService()->createContainer($options['container'], $create_container_options);
             // Container has been created. Let's retry storing blob file.
             $options['retry'] = true;
             return $this->store($filename, $data, $options);
         } else {
             throw $e;
         }
     }
 }
require_once 'vendor\\autoload.php';
use WindowsAzure\Common\ServicesBuilder;
use WindowsAzure\Blob\Models\CreateContainerOptions;
use WindowsAzure\Blob\Models\PublicAccessType;
use WindowsAzure\Common\ServiceException;
// https://azure.microsoft.com/en-us/documentation/articles/storage-php-how-to-use-blobs/
// Storage의 connection string 제공
$connectionString = "DefaultEndpointsProtocol=http;AccountName=vstechupdate;AccountKey=<어카운트키>";
// REST proxy 생성
$blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString);
$createContainerOptions = new CreateContainerOptions();
//setPublicAccess 접근 정책 설정
// CONTAINER_AND_BLOBS:
// 전체 엑세스 권한
//
// BLOBS_ONLY:
// blob들에 대해서만 읽기 권한.
$createContainerOptions->setPublicAccess(PublicAccessType::CONTAINER_AND_BLOBS);
// 컨테이너 메타데이터 설정
$createContainerOptions->addMetaData("VSTechUp", "Visual Studio");
$createContainerOptions->addMetaData("Azure", "Cloud");
try {
    // 컨테이너 생성
    $blobRestProxy->createContainer("phpcontainer", $createContainerOptions);
} catch (ServiceException $e) {
    // 에러 핸들링
    $code = $e->getCode();
    $error_message = $e->getMessage();
    echo $code . ": " . $error_message . "<br />";
}
Esempio n. 3
0
 //$containerExists = false;
 // $containers = $listContainersResult->getContainers();
 // for($i = 0; $i < $containers.length; $i++){
 // print_r($containers[$i]);
 // }
 //foreach ($listContainersResult->getContainers() as $container) {
 //    if ($container->getName() == $container) {
 //        $containerExists = true;// The container exists.
 //        // No need to keep checking.
 //        break;
 //    }
 //}
 $createContainerOptions = new CreateContainerOptions();
 //$createContainerOptions->setPublicAccess(PublicAccessType::CONTAINER_AND_BLOBS);
 //$blobRestProxy->addSignedIdentifier("uniqueid",time()+ 500,"r");
 $createContainerOptions->addMetaData("remove_action", $remove_action);
 $createContainerOptions->addMetaData("remove_access_times", $remove_access_times);
 $createContainerOptions->addMetaData("remove_hours", $remove_hours);
 try {
     $blobRestProxy->createContainer($container, $createContainerOptions);
 } catch (Exception $e) {
     $code = $e->getCode();
     // http://msdn.microsoft.com/library/azure/dd179439.aspx
     $error_message = $e->getMessage();
     if ($code == 409) {
         //The container already exist
         //error( $code.": ".$error_message); //uncomment this line for testing and to see code value and message
     }
 }
 $blob_content = file_get_contents($file['tmp_name']);
 //"$doc_code/$block_name"
require_once 'vendor\\autoload.php';
use WindowsAzure\Common\ServicesBuilder;
use WindowsAzure\Blob\Models\CreateContainerOptions;
use WindowsAzure\Blob\Models\PublicAccessType;
use WindowsAzure\Common\ServiceException;
// https://azure.microsoft.com/en-us/documentation/articles/storage-php-how-to-use-blobs/
// Storage의 connection string 제공
$connectionString = "DefaultEndpointsProtocol=http;AccountName=vstechupdate;AccountKey=<어카운트키>";
// REST proxy 생성
$blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString);
$createContainerOptions = new CreateContainerOptions();
//setPublicAccess 접근 정책 설정
// CONTAINER_AND_BLOBS:
// 전체 엑세스 권한
//
// BLOBS_ONLY:
// blob들에 대해서만 읽기 권한.
$createContainerOptions->setPublicAccess(PublicAccessType::CONTAINER_AND_BLOBS);
// 컨테이너 메타데이터 설정
$createContainerOptions->addMetaData("Webinar", "Webinar Good");
$createContainerOptions->addMetaData("Azure", "Cloud");
try {
    // 컨테이너 생성
    $blobRestProxy->createContainer("phpcontainer", $createContainerOptions);
} catch (ServiceException $e) {
    // 에러 핸들링
    $code = $e->getCode();
    $error_message = $e->getMessage();
    echo $code . ": " . $error_message . "<br />";
}
                color:white;
                text-decoration: underline;
            }
        </style>
    </head>
    
 <?php 
require_once 'vendor\\autoload.php';
use WindowsAzure\Common\ServiceBuilder;
use WindowsAzure\Blob\Models\CreateContainerOptions;
use WindowsAzure\Blob\Models\PublicAccessType;
use WindowsAzure\Common\ServiceException;
$connectionString = "DefaultEndpointsProtocol=https;AccountName=smalltalkelc;AccountKey=9Dp8HQ0qsk3ZWW1fADulCa7KEMO3Py5gOeTadrcbSwPYl+O4se+b4hfCUhDbe7KoPz+4ioJj5YSyomNcIPnyUw==";
$blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString);
$createContainerOptions = new CreateContainerOptions();
$createContainerOptions->addMetaData("key1", "value1");
$createContainerOptions->addMetaDasta("key2", "value2");
echo $connectionString;
try {
    // Create Container.
    $blobRestProxy->createContainer("mycontainer", $createContainerOptions);
} catch (ServiceException $e) {
    //Handl exception based on error codes and messages.
    //Error codes and messages are here:
    // http://msdn.microsoft.com/library/azure/dd179437.aspx
    $code = $e->getCode();
    $error_message = $e->getMessage();
    echo $code . ": " . $error_message . "<br />";
}
?>
  
require_once 'vendor\\autoload.php';
use WindowsAzure\Common\ServicesBuilder;
use WindowsAzure\Blob\Models\CreateContainerOptions;
use WindowsAzure\Blob\Models\PublicAccessType;
use WindowsAzure\Common\ServiceException;
// https://azure.microsoft.com/en-us/documentation/articles/storage-php-how-to-use-blobs/
// Storage의 connection string 제공
$connectionString = "DefaultEndpointsProtocol=http;AccountName=<저장소이름>;AccountKey=<저장소키>";
// REST proxy 생성
$blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString);
$createContainerOptions = new CreateContainerOptions();
//setPublicAccess 접근 정책 설정
// CONTAINER_AND_BLOBS:
// 전체 엑세스 권한
//
// BLOBS_ONLY:
// blob들에 대해서만 읽기 권한.
$createContainerOptions->setPublicAccess(PublicAccessType::CONTAINER_AND_BLOBS);
// 컨테이너 메타데이터 설정
$createContainerOptions->addMetaData("KCB", "Korea Community Day");
$createContainerOptions->addMetaData("Azure", "Cloud");
try {
    // 컨테이너 생성
    $blobRestProxy->createContainer("phpcontainer", $createContainerOptions);
} catch (ServiceException $e) {
    // 에러 핸들링
    $code = $e->getCode();
    $error_message = $e->getMessage();
    echo $code . ": " . $error_message . "<br />";
}
require_once 'vendor\\autoload.php';
use WindowsAzure\Common\ServicesBuilder;
use WindowsAzure\Blob\Models\CreateContainerOptions;
use WindowsAzure\Blob\Models\PublicAccessType;
use WindowsAzure\Common\ServiceException;
// https://azure.microsoft.com/en-us/documentation/articles/storage-php-how-to-use-blobs/
// Storage의 connection string 제공
$connectionString = "DefaultEndpointsProtocol=http;AccountName=xecondemo01;AccountKey=<어카운트키>";
// REST proxy 생성
$blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString);
$createContainerOptions = new CreateContainerOptions();
//setPublicAccess 접근 정책 설정
// CONTAINER_AND_BLOBS:
// 전체 엑세스 권한
//
// BLOBS_ONLY:
// blob들에 대해서만 읽기 권한.
$createContainerOptions->setPublicAccess(PublicAccessType::CONTAINER_AND_BLOBS);
// 컨테이너 메타데이터 설정
$createContainerOptions->addMetaData("XECON", "XpressEngine");
$createContainerOptions->addMetaData("Azure", "Cloud");
try {
    // 컨테이너 생성
    $blobRestProxy->createContainer("xecondevcontainer", $createContainerOptions);
} catch (ServiceException $e) {
    // 에러 핸들링
    $code = $e->getCode();
    $error_message = $e->getMessage();
    echo $code . ": " . $error_message . "<br />";
}
Esempio n. 8
0
 /**
  * create a container
  * @param type $dir name of container
  * @param type $access can be cb(CONTAINER_AND_BLOBS) or b (BLOBS_ONLY)
  * CONTAINER_AND_BLOBS:     
  * Specifies full public read access for container and blob data.
  * proxys can enumerate blobs within the container via anonymous 
  * request, but cannot enumerate containers within the storage account.
  *
  * BLOBS_ONLY:
  * Specifies public read access for blobs. Blob data within this 
  * container can be read via anonymous request, but container data is not 
  * available. proxys cannot enumerate blobs within the container via 
  * anonymous request.
  * If this value is not specified in the request, container data is 
  * private to the account owner.
  * @return boolean
  */
 protected function createContainer($dir, $access = 'cb', array $metadata = array())
 {
     $createContainerOptions = new CreateContainerOptions();
     switch ($access) {
         case 'cb':
             $createContainerOptions->setPublicAccess(PublicAccessType::CONTAINER_AND_BLOBS);
             break;
         case 'b':
             $createContainerOptions->setPublicAccess(PublicAccessType::BLOBS_ONLY);
             break;
         default:
             $createContainerOptions->setPublicAccess(PublicAccessType::CONTAINER_AND_BLOBS);
     }
     foreach ($metadata as $key => $value) {
         $createContainerOptions->addMetaData($key, $value);
     }
     try {
         // Create container.
         $this->blobRestProxy->createContainer($dir, $createContainerOptions);
         return true;
     } catch (ServiceException $e) {
         // Handle exception based on error codes and messages.
         // Error codes and messages are here:
         // http://msdn.microsoft.com/it-it/library/windowsazure/dd179439.aspx
         $code = $e->getCode();
         $error_message = $e->getMessage();
         echo $code . ": " . $error_message . "<br />";
         return false;
     }
 }