C#没有从Azure blob存储中检索blob(C# not retrieving blob from Azure blob storage)

编程入门 行业动态 更新时间:2024-10-12 01:24:35
C#没有从Azure blob存储中检索blob(C# not retrieving blob from Azure blob storage)

我有一系列我想要处理的blob。 我的程序收到404错误,抛出这样的异常:

ErrorCode:BlobNotFound ErrorMessage:The specified blob does not exist.

正确设置了容器上的访问策略,当我将记录的URI粘贴到我的浏览器中时(例如,这个: https://atpblob.blob.core.windows.net/darkskydata/plot1251time2010-01-02t00:00:01z.json ),它下载得很好。

这是相关的代码:

Console.WriteLine(daily.BlobUri); CloudBlockBlob blockBlob = container.GetBlockBlobReference(daily.BlobUri); string text; using (var memoryStream = new MemoryStream()) { blockBlob.DownloadToStream(memoryStream); text = System.Text.Encoding.UTF8.GetString(memoryStream.ToArray()); } Console.WriteLine(text);

我究竟做错了什么?

I have a series of blobs which I would like to process. My program is getting a 404 error, throwing an exception like this:

ErrorCode:BlobNotFound ErrorMessage:The specified blob does not exist.

The access policy on the container is set properly, and when I paste the logged URI into my browser (for instance, this: https://atpblob.blob.core.windows.net/darkskydata/plot1251time2010-01-02t00:00:01z.json), it downloads fine.

Here is the relevant code:

Console.WriteLine(daily.BlobUri); CloudBlockBlob blockBlob = container.GetBlockBlobReference(daily.BlobUri); string text; using (var memoryStream = new MemoryStream()) { blockBlob.DownloadToStream(memoryStream); text = System.Text.Encoding.UTF8.GetString(memoryStream.ToArray()); } Console.WriteLine(text);

What am I doing wrong?

最满意答案

我相信问题在于以下代码行:

CloudBlockBlob blockBlob = container.GetBlockBlobReference(daily.BlobUri);

如果查看GetBlockBlobReference文档,预期的参数实际上是blob的名称而不是URL。

请尝试将其更改为blob的名称。 出于测试目的,请尝试以下代码:

CloudBlockBlob blockBlob = container.GetBlockBlobReference("plot1251time2010-01-02t00:00:01z.json");

你不应该得到一个错误。

I believe the problem is with the following line of code:

CloudBlockBlob blockBlob = container.GetBlockBlobReference(daily.BlobUri);

If you look at GetBlockBlobReference documentation, the parameter expected is actually blob's name and not the URL.

Please try changing it to blob's name. For testing purpose, please try the following code:

CloudBlockBlob blockBlob = container.GetBlockBlobReference("plot1251time2010-01-02t00:00:01z.json");

You should not get an error.

更多推荐

本文发布于:2023-04-29 03:32:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1334457.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:blob   Azure   storage   retrieving

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!