【问题标题】:How display a list of Azure blob of a Container in Silverlight application?如何在 Silverlight 应用程序中显示容器的 Azure blob 列表?
【发布时间】:2012-01-27 07:03:23
【问题描述】:

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

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

类似这样的东西,但对于 Silverlight:

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

CloudBlobClient blobClient = account.CreateCloudBlobClient();

IEnumerable<CloudBlobContainer> containers = blobClient.ListContainers()

谢谢

【问题讨论】:

    标签: silverlight azure-blob-storage


    【解决方案1】:

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

    1. 基于 .NET 的 API - 这是您在常规 .NET 应用程序中使用过的 API - 但是此 API 不能在 Silverlight 应用程序中使用
    2. RESTfull HTTP API - 这是您可以直接从 Silverlight 使用的那个

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

    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.
    
    
        }
    

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

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

    你可以阅读更多关于options here.

    希望对您有所帮助。

    【讨论】:

      【解决方案2】:

      好吧,这里没有魔法。我可以使用 API 或(我将要做的)使用 WCF 服务来获取 Azure blob 存储,并在我的 Silverlight 应用程序中通过此服务来获取数据。
      不神奇,但并不复杂。

      【讨论】:

        猜你喜欢
        • 2020-07-15
        • 1970-01-01
        • 2022-01-15
        • 2014-03-04
        • 2019-04-17
        • 2021-04-19
        • 1970-01-01
        • 2011-05-18
        • 2015-11-10
        相关资源
        最近更新 更多