2
votes

I'm very new to microsoft azure. I have been given the task to list all the files in the azure blob storage container. Below are the details which i'm having for the task

i'm having below details:

Storage Account - accdevtesthw

Storage account type - blob

Container Name - Students

Folders - Marks & Details

Storage Account key -

Please let me know how to get the REST URL to list all the files in Marks folder in my container.

i tried with below URL, but failed with the error mentioned

https://accdevtesthw.blob.core.windows.net/Students/Marks?comp=list

error:

<Error>
        <Code>InvalidQueryParameterValue</Code>
        <Message>
        Value for one of the query parameters specified in the request URI is invalid. RequestId:90a650f3-601e-008e-62b3-e3ab45000000 Time:2019-03-26T09:06:07.8146066Z
        </Message>
        <QueryParameterName>comp</QueryParameterName>
        <QueryParameterValue>list</QueryParameterValue>
        <Reason/>a
        </Error>

I want to know how to frame RESTURL with the details i have been given

2
you want to just use the api you provided to list blobs(with tools like postman) or use code to list blobs?Ivan Yang

2 Answers

1
votes

I had the same issue. I solved it by adding the 'prefix' parameter in the Uri. In your case I think you need:

https://accdevtesthw.blob.core.windows.net/Students?comp=list&prefix=Marks

from: https://docs.microsoft.com/en-us/rest/api/storageservices/list-blobs#uri-parameters

1
votes

Refer to the suggestion mentioned in this SO thread

The List Blobs operation enumerates the list of blobs under the specified container.

Try this code.  Basically, the thing to do is check the type on each of the IListBlobItems returned:

var blobs = CloudStorageAccount.DevelopmentStorageAccount.CreateCloudBlobClient();
var container = blobs.GetContainerReference("testcontainer");
container.CreateIfNotExist();
container.GetBlobReference("directory/blob.txt").UploadText(string.Empty);
container.GetBlobReference("blob.txt").UploadText(string.Empty);

var items = container.ListBlobs();

Console.WriteLine("Directories:");
foreach (var dir in items.OfType<CloudBlobDirectory>())
{
  Console.WriteLine("\t{0}", dir.Uri);
}

Console.WriteLine("Blobs:");
foreach (var blob in items.OfType<CloudBlob>())
{
  Console.WriteLine("\t{0}", blob.Uri);
}

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
            CloudBlobContainer container = blobClient.GetContainerReference("aaa");

            foreach (IListBlobItem blobItem in container.ListBlobs())
            {
                if (blobItem is CloudBlobDirectory)
                {
                    CloudBlobDirectory directory = (CloudBlobDirectory)blobItem;
                    IEnumerable<IListBlobItem> blobs = directory.ListBlobs(true);
                    ICloudBlob bi;
                    foreach (var blob in blobs)
                    {
                        if (blob is CloudPageBlob)
                        {
                            bi = blob as CloudPageBlob;
                            Console.WriteLine(bi.Name);
                            Console.WriteLine(bi.Properties.LastModified.ToString());
                            Console.WriteLine();
                            Console.WriteLine(@"==========================");
                        }
                    }
                }
            }

For more information you may refer to the suggestion mentioned in this SO link

Kindly let us know if the above helps or you need further assistance on this issue.