Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure GetBlockBlobReference未提供文件夹路径详细信息_Azure_Azure Storage_Azure Storage Blobs_Azure Blob Storage - Fatal编程技术网

Azure GetBlockBlobReference未提供文件夹路径详细信息

Azure GetBlockBlobReference未提供文件夹路径详细信息,azure,azure-storage,azure-storage-blobs,azure-blob-storage,Azure,Azure Storage,Azure Storage Blobs,Azure Blob Storage,我正在尝试从Azure storage explorer下载块blob。我能够下载容器根目录中存在的所有块blob。我无法下载嵌套在容器内子文件夹中的blob CloudBlockBlob blob = container.GetBlockBlobReference(fileName); SharedAccessBlobPolicy sasConstraints = new SharedAccessBlobPolicy();

我正在尝试从Azure storage explorer下载块blob。我能够下载容器根目录中存在的所有块blob。我无法下载嵌套在容器内子文件夹中的blob

        CloudBlockBlob blob = container.GetBlockBlobReference(fileName);

        SharedAccessBlobPolicy sasConstraints = new SharedAccessBlobPolicy();            
        sasConstraints.SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddHours(1);
        sasConstraints.Permissions = SharedAccessBlobPermissions.Read;

        string sasBlobToken = blob.GetSharedAccessSignature(sasConstraints);

        return blob.Uri.AbsoluteUri + sasBlobToken;

只需使用from Gaurav Mantri中提到的
ListBlobs
,即可检索所需子文件夹中的所有文件(blob)。然后迭代并下载:

var storageAccount = CloudStorageAccount.Parse("yourConnectionString");
var client = storageAccount.CreateCloudBlobClient();
var container = client.GetContainerReference("yourContainer");
var blobs = container.ListBlobs(prefix: "subdirectory1/subdirectory2", useFlatBlobListing: true);
foreach (var blob in blobs) 
{
    blob.DownloadToFileAsync("yourFilePath");
}

我无法使用GetBlockBlobReference(文件名)获取blockBlob的绝对路径。下面的代码解决了我的问题。我得到了清单,然后使用LINQ获得了带有绝对路径细节的blockBlob。


如果有任何其他有效方法可以从容器中的目录列表中提取blob信息,请更正。下面的解决方案有助于访问目录(或文件夹路径)下的单个文件绝对路径


希望这能帮助尝试访问基于多级目录(Level1/Level2/Level3)路径的Blob文件路径的人。

我不知道你的意思。Blob存储没有子文件夹的概念。只有虚拟文件夹。你能更好地描述你正在努力实现的目标吗?发布的代码显示了如何下载单个blob。所谓子文件夹,我指的是文件夹中的文件夹。我已在容器中创建了多个文件夹。您是要下载虚拟文件夹中的所有blob,还是要下载虚拟文件夹中的单个blob?文件夹仅在其中包含文件时才存在(因为文件夹实际上只是文件名的一部分)。你有文件吗?可能是
        do
        {
            var listingResult = await blobDirectory.ListBlobsSegmentedAsync(useFlatBlobListing, blobListingDetails, maxBlobsPerRequest, continuationToken, null, null);


           //The below lined fetched the blockBlob with the correct directory details.
            var blockBlob = listingResult.Results.Where(x => x.Uri.AbsolutePath.Contains(fileName)).Count()>0 ? (CloudBlockBlob)listingResult.Results.Where(x=>x.Uri.AbsolutePath.Contains(fileName)).FirstOrDefault():null;

            if (blockBlob != null)
            {                    
                sasConstraints.SharedAccessExpiryTime = expiryTimeSAS;
                sasConstraints.Permissions = SharedAccessBlobPermissions.Read;                    
                string sasBlobToken = blockBlob.GetSharedAccessSignature(sasConstraints);                    
                return blockBlob.Uri.AbsoluteUri + sasBlobToken;                    
            }                
            continuationToken = listingResult.ContinuationToken;                

        } while (continuationToken != null);
public static String GetBlobUri(string dirPath, string fileName)
      {
           //Get a reference to a blob within the container.
         CloudStorageAccount storageAccount = CloudStorageAccount.Parse("Blob Key");
          CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
          CloudBlobContainer container = blobClient.GetContainerReference("Blob Container");
          CloudBlockBlob blockBlob = container.GetBlockBlobReference(dirPath+fileName);

        return blockBlob.Uri.AbsoluteUri;
    }