c# - Azure.RequestFailedException : 'Service request failed. 状态 : 404 (The specified blob does not exist. )错误代码:BlobNotFound

标签 c# azure azure-blob-storage azure-data-lake

亲爱的开发者您好,

我面临的问题是无法读取/访问我的 Azure 存储帐户上的 blob 文件。我使用 C# 作为编程语言。最后,我想读取我的 blob 文件来搜索特定值并检查其是否为真。预先感谢您<3

这就是我的代码的样子。

            //Get a reference to the edc(1.3) container
            string containerName = "edc/rchexport/rch-bu-party-dd/1.3";
            string connectionString = "DefaultEndpointsProtocol=https;AccountName=adlse3.....";
        
        Log.Information($"C# Timer trigger function executed at: {DateTime.Now}");
        BlobContainerClient blobContainerClient = new BlobContainerClient(connectionString, containerName);
        

        //Acces to parquet blob file. Getting the sample structure of the blob to create the final table. 
        string edcRchBuParty = "rchtestdata.parquet";
        BlobClient st5BobClient = blobContainerClient.GetBlobClient(edcRchBuParty);
        var sampleStream = st5BobClient.OpenRead();   **<<<<<<<<< This where the error pops up**.
        var sampleReader = new ParquetReader(sampleStream);

        Table sampleTable = sampleReader.ReadAsTable();
        DataField[] datafields = sampleTable.Schema.GetDataFields();
        Table finalTable = new Table(datafields);
        //looping through the container for getting the blobs and read the file and add the rows to the final table 
        await foreach (BlobItem blobItem in blobContainerClient.GetBlobsAsync())
        {
            if (blobItem.Name.Contains("15b0251556c74fd693ca1f3cb4ce4d6e")) //for testing
            {
                Log.Information("\t" + blobItem.Name);
                BlobClient blobClient = blobContainerClient.GetBlobClient(blobItem.Name);
                var stream = blobClient.OpenRead();  
                var reader = new ParquetReader(stream);
                Table table = reader.ReadAsTable();
                Console.WriteLine("Step 3 : Check");
                foreach (Row row in table)
                {
                    finalTable.Add(row);
                }
                Log.Information(finalTable.Count.ToString());
            }

最佳答案

问题在于您如何指定容器名称。

查看您的代码,我猜测您的容器名称是 edc 并且您的 blob (rchtestdata.parquet) 存在于像 rchexport/这样的文件夹层次结构中rch-bu-party-dd/1.3

如果是这种情况,请更改以下代码行:

string containerName = "edc/rchexport/rch-bu-party-dd/1.3";

string containerName = "edc";

并更改以下代码行:

string edcRchBuParty = "rchtestdata.parquet";

string edcRchBuParty = "rchexport/rch-bu-party-dd/1.3/rchtestdata.parquet";

那么您不应该收到此错误。

关于c# - Azure.RequestFailedException : 'Service request failed. 状态 : 404 (The specified blob does not exist. )错误代码:BlobNotFound,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69647791/

相关文章:

c# - 为什么 antlr3 c# 解析器方法是私有(private)的?

c# - List.AddRange 调用 List.Add 吗?

python - 设置在使用 BlobServiceClient 创建的 Azure Blob 容器中的生存时间

c# - 扫描 Windows 进程列表的最有效方法?

Azure 子网 - 您的子网不包含在该虚拟网络的同一地址空间内

azure - 应用服务监听器中的数字证书 CN 名称和主机名

javascript - 将 MSAL.js 用于 NodeJ

json - ConvertFrom-Json : Invalid JSON primitive:

c# - 设置 Azure 存储操作的超时

c# - .NET 类及其源代码