如何在Silverlight应用程序中显示容器的Azure Blob列表? [英] How display a list of Azure blob of a Container in Silverlight application?

查看:54
本文介绍了如何在Silverlight应用程序中显示容器的Azure Blob列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Silverlight应用程序中显示容器的Azure blob列表?

How display a list of Azure blob of a Container in Silverlight application?

我知道如何在常规.Net中执行此操作,但是在Silverlight中需要. 我可以上传,但我要显示已上传内容的列表.

I know how to do it in regular .Net but I need it in Silverlight. I'm able to upload but I want to show a list of what already uploaded.

类似这样,但对于Silverlight:

Something like this but for Silverlight:

CloudStorageAccount account =
            CloudStorageAccount.FromConfigurationSetting("DataConnectionString");

CloudBlobClient blobClient = account.CreateCloudBlobClient();

IEnumerable<CloudBlobContainer> containers = blobClient.ListContainers()

谢谢

推荐答案

有两种与Azure Blob存储进行通信的方式:

There are two ways to communicate with Azure Blob Storage:

  1. 基于.NET的API-这是您在常规.NET应用程序中使用的API-但是,不能在Silverlight应用程序中使用此API
  2. REST完整的HTTP API -这就是您所需要的可能直接从Silverlight使用
  1. .NET based API - this is the one, that you have used in regular .NET app - however this one cannot be used from within Silverlight application
  2. RESTfull HTTP API - this is the one that you might use directly from Silverlight

但是,没有内置库.您将必须自己编写HTTP请求.可能有点复杂,看起来像这样:

There is however no build-in library. You will have to write the HTTP requests on your own. That might be little complicated, and it will look something like this:

private void ListFiles()
    {
        var uri = String.Format("{0}{1}", _containerUrl, "?restype=container&comp=list&include=snapshots&include=metadata");

        _webRequest = (HttpWebRequest)WebRequestCreator.ClientHttp.Create(new Uri(uri));
        _webRequest.BeginGetResponse(EndListFiles, Guid.NewGuid().ToString());
    }

    private void EndListFiles(IAsyncResult result)
    {
        var doc = _webRequest.EndGetResponse(result);

        var xDoc = XDocument.Load(doc.GetResponseStream());
        var blobs = from blob in xDoc.Descendants("Blob")
                    select ConvertToUserFile(blob);
    //do whatever you need here with the blobs.


    }

请注意,这假设该容器是公共的.如果您的容器不是公开的,那么您将有两种选择:

Please note, that this supposes, that the container is public. If your container is not public, than you would have two options:

  1. 使用应用程序密钥对HTTP请求进行签名-这通常是个坏主意,同时您将访问密钥提供给silverlight应用程序(可能通过Internet分发).
  2. 使用共享访问签名

您可以在此处详细了解选项.

You can read more about the options here.

希望有帮助.

这篇关于如何在Silverlight应用程序中显示容器的Azure Blob列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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