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

后端 未结 2 1146
北海茫月
北海茫月 2021-01-28 21:14

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

I know how to do it in regular .Net but I need it in Silverlight. I\'m able

相关标签:
2条回答
  • 2021-01-28 21:21

    Okay no magic here. I can use the API or (what I will do) use a WCF Service to fetch Azure blob storage and pass thru this service in my Silverlight application to get the data.
    Not magic but not complicated.

    0 讨论(0)
  • 2021-01-28 21:38

    There are two ways to communicate with Azure Blob Storage:

    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

    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. Sign your HTTP request with the application key - that is generally bad ideas, while you are giving your access key to the silverlight applications (which might be distributed over the internet).
    2. Use Shared Access Signatures

    You can read more about the options here.

    Hope that helps.

    0 讨论(0)
提交回复
热议问题