2016-08-08 30 views
0

因此,我已經下載了Azure SDK for php並啓動了模擬器。一切還好。
然後我複製&粘貼的代碼Microsoft,所以我可以創建一個新的測試容器。使用Azure存儲模擬器返回404

require_once 'vendor\autoload.php'; 
use WindowsAzure\Common\ServicesBuilder; 
use MicrosoftAzure\Storage\Blob\Models\CreateContainerOptions; 
use MicrosoftAzure\Storage\Blob\Models\PublicAccessType; 
use MicrosoftAzure\Storage\Common\ServiceException; 

// Create blob REST proxy. 
$blobRestProxy = ServicesBuilder::getInstance()->createBlobService('UseDevelopmentStorage=true'); 


// OPTIONAL: Set public access policy and metadata. 
// Create container options object. 
$createContainerOptions = new CreateContainerOptions(); 

// Set public access policy. Possible values are 
// PublicAccessType::CONTAINER_AND_BLOBS and PublicAccessType::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. 
$createContainerOptions->setPublicAccess(PublicAccessType::CONTAINER_AND_BLOBS); 

// Set container metadata. 
$createContainerOptions->addMetaData("key1", "value1"); 
$createContainerOptions->addMetaData("key2", "value2"); 

try { 
    // Create container. 
    $blobRestProxy->createContainer("mycontainer", $createContainerOptions); 
} catch (ServiceException $e) { 
    // Handle exception based on error codes and messages. 
    // Error codes and messages are here: 
    // http://msdn.microsoft.com/library/azure/dd179439.aspx 
    $code = $e->getCode(); 
    $error_message = $e->getMessage(); 
    echo $code . ": " . $error_message . "<br />"; 
} 

當我運行這段代碼時,我得到一個很好的錯誤信息。

404:失敗:
代碼:404
值:指定的資源不存在。

這是怎麼回事?我正在用盡想法。首先,我有一個稍微不同的代碼,但它們都不起作用,所以現在我嘗試直接從MS使用此示例,但沒有運氣。

CLI顯示模擬器正在運行並且端點正確。

回答

1

我使用Fiddler來捕獲由SDK生成的http請求,url路徑爲/testcontainer?restype=container。根據Rest API指南https://msdn.microsoft.com/en-us/library/azure/dd179468.aspx,url路徑應爲/devstoreaccount1/mycontainer?restype=container

目前,在本地模擬器上使用Azure存儲開發了一種解決方法。每次使用容器名稱時,我們都可以添加本地帳戶名稱devstoreaccount1,例如

$blobRestProxy->createContainer("devstoreaccount1/testcontainer"); 
$blobRestProxy->createBlockBlob("devstoreaccount1/testcontainer", "testblob", "test string"); 
$blobRestProxy->listBlobs("devstoreaccount1/testcontainer"); 

任何進一步的問題,請隨時讓我知道。

+0

完美!謝謝。我只是想知道爲什麼沒有記錄在任何地方: - /或者我錯過了某處?這顯然是一個阻止人們使用它的大錯誤。 – walther

相關問題