IT Share you

Azure 저장소 위치에 하위 컨테이너를 만드는 방법

shareyou 2020. 11. 30. 20:14
반응형

Azure 저장소 위치에 하위 컨테이너를 만드는 방법


Azure 저장소 위치에 하위 컨테이너를 만드는 방법.

알려주세요


Windows Azure는 계층 적 컨테이너의 개념을 제공하지 않지만 규칙 및 API에 따라 계층 구조를 탐색하는 메커니즘을 제공합니다. 모든 컨테이너는 동일한 수준에 저장됩니다. Blob 이름에 대한 명명 규칙을 사용하여 유사한 기능을 얻을 수 있습니다.

예를 들어 "content"라는 컨테이너를 만들고 해당 컨테이너에 다음 이름으로 Blob을 만들 수 있습니다.

content/blue/images/logo.jpg
content/blue/images/icon-start.jpg
content/blue/images/icon-stop.jpg

content/red/images/logo.jpg
content/red/images/icon-start.jpg
content/red/images/icon-stop.jpg

참고 이러한 모양은 당신의 "내용"컨테이너에 대한 단순 목록 있음. 즉, "/"를 일반적인 구분 기호로 사용하면 계층 적 방식으로이를 순회하는 기능을 제공합니다.

protected IEnumerable<IListBlobItem> 
          GetDirectoryList(string directoryName, string subDirectoryName)
{
    CloudStorageAccount account =
        CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
    CloudBlobClient client = 
        account.CreateCloudBlobClient();
    CloudBlobDirectory directory = 
        client.GetBlobDirectoryReference(directoryName); 
    CloudBlobDirectory subDirectory = 
        directory.GetSubdirectory(subDirectoryName); 

    return subDirectory.ListBlobs();
}

그런 다음이를 다음과 같이 호출 할 수 있습니다.

GetDirectoryList("content/blue", "images")

참고 사용 GetBlobDirectoryReferenceGetSubDirectory 방법과 CloudBlobDirectory 형 대신 CloudBlobContainer을 . 이것들은 당신이 찾고있는 순회 기능을 제공합니다.

이것은 시작하는 데 도움이 될 것입니다. 질문에 대한 답변이 없으면 알려주세요.

[ 영감 주신 Neil Mackenzie 에게 감사드립니다 ]


Blob Storage를 언급하고 있습니까? 그렇다면 계층 구조는 단순히 StorageAccount / Container / BlobName입니다. 중첩 된 컨테이너가 없습니다.

즉, Blob 이름에 슬래시를 사용하여 URI의 중첩 컨테이너를 시뮬레이션 할 수 있습니다. 이름 지정에 대한 자세한 내용 은 MSDN의이 문서를 참조 하십시오.


나는 tobint 답변에 동의 하고이 디렉토리를 생성하여 Azure Storage에 내 게임 html을 업로드하는 것과 동일한 방법이 필요하기 때문에이 상황을 추가하고 싶습니다.

  • Games \ Beautyshop \ index.html
  • Games \ Beautyshop \ assets \ apple.png
  • Games \ Beautyshop \ assets \ aromas.png
  • Games \ Beautyshop \ customfont.css
  • Games \ Beautyshop \ jquery.js

그래서 귀하의 추천 후 Azure Storage Explorer 도구로 내 콘텐츠를 업로드하려고 시도했으며 다음 URL로 도구 및 소스 코드를 다운로드 할 수 있습니다 : Azure Storage Explorer

우선 도구를 통해 업로드하려고했지만 필요하지 않기 때문에 계층 적 디렉터리 업로드를 허용하지 않습니다. Blob 컨테이너에 하위 디렉터리를 만드는 방법

마지막으로 Azure Storage Explorer 소스 코드를 디버깅하고 StorageAccountViewModel.cs 파일에서 Background_UploadBlobs 메서드와 UploadFileList 필드를 편집했습니다. 원하는대로 편집 할 수 있습니다. 철자 오류를 만들었을 수 있습니다. : / 정말 미안하지만 그게 내 추천입니다.


컨테이너에 하위 폴더를 만들려면 파일을 업로드하는 동안 고급 옵션으로 이동하여 폴더에 업로드를 선택하면 컨테이너에 새 폴더가 만들어지고 여기에 파일이 업로드됩니다.


샘플 코드

string myfolder = "<folderName>";
string myfilename = "<fileName>";
string fileName = String.Format("{0}/{1}.csv", myfolder, myfilename);
CloudBlockBlob blob = container.GetBlockBlobReference(fileName);

참고 URL : https://stackoverflow.com/questions/3183857/how-to-create-a-sub-container-in-azure-storage-location

반응형