因此,我已經下載了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顯示模擬器正在運行並且端點正確。
完美!謝謝。我只是想知道爲什麼沒有記錄在任何地方: - /或者我錯過了某處?這顯然是一個阻止人們使用它的大錯誤。 – walther