3

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

1
  • you want to just use the api you provided to list blobs(with tools like postman) or use code to list blobs? Commented Mar 27, 2019 at 6:17

2 Answers 2

1

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://learn.microsoft.com/en-us/rest/api/storageservices/list-blobs#uri-parameters

Sign up to request clarification or add additional context in comments.

1 Comment

To make this work, I also had to add restype=container: https://accdevtesthw.blob.core.windows.net/Students?restype=container&comp=list&prefix=Marks
1

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);
}
Or You may try this option too

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.