REST API的指针以访问或列出Blob存储容器中的文件

时间:2019-03-26 09:21:20

标签: azure-storage azure-blob-storage

我对Microsoft Azure非常陌生。我已经获得了列出azure blob存储容器中所有文件的任务。 以下是我为该任务准备的详细信息

我有以下详细信息:

存储帐户-accdevtesthw

存储帐户类型-Blob

容器名称-学生

文件夹-标记和详细信息

存储帐户密钥-

请让我知道如何获取REST URL来列出容器中Marks文件夹中的所有文件。

我尝试使用下面的URL,但由于提到的错误而失败

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

错误:

<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>

我想知道如何使用我提供的详细信息来构造RESTURL

2 个答案:

答案 0 :(得分:0)

请参阅此SO主题中提到的建议

List Blobs操作枚举指定容器下的blob列表。

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(@"==========================");
                        }
                    }
                }
            }

有关更多信息,您可以参考此SO链接中提到的建议

请告知我们以上内容是否对您有帮助,或者您在此问题上需要进一步的帮助。

答案 1 :(得分:0)

我有同样的问题。我通过在Uri中添加'prefix'参数来解决此问题。对于您的情况,我认为您需要:

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

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