2016-08-08 4 views
0

그래서 저는 PHP 용 Azure SDK를 다운로드하고 에뮬레이터를 시작했습니다. 모든 것이 괜찮아.
그런 다음 Microsoft의 붙여 넣기 코드 &을 복사하므로 새 테스트 컨테이너를 만들 수 있습니다.Azure Storage Emulator로 돌아 가기 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

필자는 SDK에서 생성 한 http 요청을 캡처하기 위해 URL 경로를 /testcontainer?restype=container으로 설정했습니다. 나머지 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

Perfect! 고맙습니다. 나는 왜 이것이 어디서 문서화되지 않았는지 궁금하다. - 아니면 어딘가에 놓쳤을 까? 그것은 분명히 사람들이 그것을 사용하는 것을 막는 커다란 버그입니다. – walther