Azure のコンテナー内のすべての BLOB のリストを取得するにはどうすればよいでしょうか? 質問する

Azure のコンテナー内のすべての BLOB のリストを取得するにはどうすればよいでしょうか? 質問する

Azure のストレージ アカウントのアカウント名とアカウント キーがあります。そのアカウントのコンテナー内のすべての BLOB のリストを取得する必要があります。(「$logs」コンテナー)

CloudBlobClient クラスを使用して特定の BLOB の情報を取得することはできますが、$logs コンテナー内のすべての BLOB のリストを取得する方法がわかりません。

ベストアンサー1

コンテナ内のすべてのBLOBを一覧表示するサンプルは、https://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-how-to-use-blobs/#コンテナー内の blobs の一覧:

// Retrieve the connection string for use with the application. The storage
// connection string is stored in an environment variable on the machine
// running the application called AZURE_STORAGE_CONNECTION_STRING. If the
// environment variable is created after the application is launched in a
// console or with Visual Studio, the shell or application needs to be closed
// and reloaded to take the environment variable into account.
string connectionString = Environment.GetEnvironmentVariable("AZURE_STORAGE_CONNECTION_STRING");

// Create a BlobServiceClient object which will be used to create a container client
BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);

// Get the container client object
BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient("yourContainerName");

// List all blobs in the container
await foreach (BlobItem blobItem in containerClient.GetBlobsAsync())
{
    Console.WriteLine("\t" + blobItem.Name);
}    

おすすめ記事