【问题标题】:Azure Storage Container ListBlobs throw Uri NULL exception after upgrade storage to 4.0.1Azure 存储容器 ListBlobs 将存储升级到 4.0.1 后引发 Uri NULL 异常
【发布时间】:2015-01-31 02:27:12
【问题描述】:

当我将 azure storage 从 1.8 升级到 4.0.1 时,以下代码不再起作用。

var myUri = new Uri(generatedURLwithSAS);
var sasContainer = new CloudBlobContainer(myUri);
var result0 = sasContainer.ListBlobs();
Console.WriteLine(result0);

使用 storage 4.0.1,代码抛出异常:

Exception Type: Microsoft.WindowsAzure.Storage.StorageException
Exception: Value cannot be null.
Parameter name: uriString
Stack Trace: 
at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd,     IRetryPolicy policy, OperationContext operationContext)
at Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer.<>c__DisplayClassf.<ListBlobs>b__e(IContinuationToken token)at Microsoft.WindowsAzure.Storage.Core.Util.CommonUtility.<LazyEnumerable>d__0`1.MoveNext()

Exception Type: System.ArgumentNullException
Exception: Value cannot be null.
Parameter name: uriString
Stack Trace: 
at System.Uri..ctor(String uriString)
at Microsoft.WindowsAzure.Storage.Blob.Protocol.ListBlobsResponse.<ParseXml>d__0.MoveNext()
at Microsoft.WindowsAzure.Storage.Shared.Protocol.ResponseParsingBase`1.<ParseXmlAndClose>d__6.MoveNext()
at Microsoft.WindowsAzure.Storage.Shared.Protocol.ResponseParsingBase`1.<get_ObjectsToParse>d__0.MoveNext()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer.<ListBlobsImpl>b__4a(RESTCommand`1 cmd, HttpWebResponse resp, OperationContext ctx)
at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ProcessEndOfRequest[T](ExecutionState`1 executionState)
at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext)

知道如何让它工作吗?

我知道我可以使用 account 和 accountkey 创建凭据来访问容器和列出 blob,但我想知道如何仅使用带有 SAS 的 blob 路径来执行此操作。

任何建议将不胜感激。

【问题讨论】:

    标签: c# azure azure-storage


    【解决方案1】:

    您在下面提供的 SAS 令牌是使用旧版本的存储客户端库生成的。客户端库只能与 REST 协议的一个版本通信。使用旧客户端生成的 SAS 令牌强制执行旧 REST 版本的服务端操作,但新客户端使用 2014 REST 版本语义来解释响应。 这会发生故障,因为这些 REST 版本之间的 ListBlobs XML 响应发生了重大变化,因此新的客户端库无法正确解析该 XML。

    这里有一些关于对 SAS 令牌的一些更改可能有用的更多信息,包括 api-version 参数:http://blogs.msdn.com/b/windowsazurestorage/archive/2014/05/14/what-s-new-for-microsoft-azure-storage-at-teched-2014.aspx

    请尝试使用 4.0.1 版本的客户端库重新生成令牌,您的代码应该可以按预期工作。

    【讨论】:

      猜你喜欢
      • 2021-01-24
      • 1970-01-01
      • 2019-07-24
      • 2016-02-17
      • 1970-01-01
      • 2022-01-21
      • 2020-07-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多