使用其URI获取对Blob的引用 [英] Getting a reference to a blob using its URI

查看:183
本文介绍了使用其URI获取对Blob的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何通过URI获取Blob引用?

我正在像这样引用blob:

I'm getting a reference to a blob like so:

        var blob = new CloudBlockBlob(new Uri("https://xxxx.blob.core.windows.net/input/DisabledFlights[1].cache"));

我获得此URL的方法是通过门户网站:

The way I got this URL, is through the portal:

尝试下载时:

            await blob.DownloadToStreamAsync(stream);

我遇到以下异常:

[7/17/2019 4:25:27 PM] Executed 'sFtpSender' (Failed, Id=4943c931-5850-4dc8-abe4-c111ed6bbfa9)
[7/17/2019 4:25:27 PM] System.Private.CoreLib: Exception while executing function: sFtpSender. Microsoft.WindowsAzure.Storage: The specified resource does not exist.

我在做什么错?如何获得对Blob的引用?

推荐答案

根据错误消息,我认为blob在私有容器中.

As per the error message, I think the blob is in private container.

有两种方法可以使用其uri获取Blob引用.

There're 2 methods for get a blob reference using its uri.

方法1 :将容器访问级别更改为Blob级别或容器级别,然后可以直接使用以下代码:

Method 1: Change the container Access Level to Blob level or Container level, then you can directly use the code below:

var blob = new CloudBlockBlob(new Uri("https://xxxx.blob.core.windows.net/input/DisabledFlights[1].cache"));

await blob.DownloadToStreamAsync(stream);

方法2 :如果要将容器保留为私有,则在启动CloudBlockBlob()时,应在其中指定StorageCredentials,如下所示:

Method 2:If you want to keep the container as private, when initiate a CloudBlockBlob(), you should specify StorageCredentials within it, like below:

//besides using sas token, you can also use other way to construct StorageCredentials, like using account_name / account_key.
var blob = new CloudBlockBlob(new Uri("https://xxxx.blob.core.windows.net/input/DisabledFlights[1].cache"), ,new StorageCredentials("sasToken"));

await blob.DownloadToStreamAsync(stream);

这篇关于使用其URI获取对Blob的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆