【问题标题】:Azure java: SAS identifier cannot be found for specified signed identifierAzure java:找不到指定签名标识符的 SAS 标识符
【发布时间】:2017-03-24 14:23:13
【问题描述】:

我正在使用 SDK for java 来创建 SAS 来访问 blob。 这是代码:

SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy();
policy.setPermissionsFromString("r");
Calendar date = Calendar.getInstance();
Date expire = new Date(date.getTimeInMillis() + (expirationMinutes * 60000));
Date start = new Date(date.getTimeInMillis());
policy.setSharedAccessExpiryTime(expire);
policy.setSharedAccessStartTime(start);
return blob.getUri().toString()+"?"+blob.generateSharedAccessSignature(policy, externalFileName);

但是当我尝试使用 url 访问 blob 时,我收到此错误:

<Error>
<Code>AuthenticationFailed</Code>
<Message>
Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. RequestId:f1f169d2-0001-003f-115a-3be1d6000000 Time:2016-11-10T13:57:14.6192554Z
</Message>
<AuthenticationErrorDetail>
SAS identifier cannot be found for specified signed identifier
</AuthenticationErrorDetail>
</Error>

我在 NET 中为同一个 blob 做同样的事情,结果 url(有效)与我在这里得到的不同:

不起作用(java):

/mycontainer/privadoPrueba/cat1.jpg?sig=FFLVk%2FPViHBZhH1JIW6wBbWiJ0%2Bgz0U8wjFzgRoytNo%3D&st=2016-11-10T13%3A55%3A06Z&se=2016-11-10T14%3A06%3A06Z&sv=2015-07-08&si=privadoPrueba%2Fcat1.jpg&sp=r&sr=b

作品(网络):

/mycontainer/privadoPrueba/cat1.jpg?sv=2015-07-08&sr=b&sig=WyiJWltZFj1AkkzST6mo2NjBF1tRSXxrkMP5LEAGJNk%3D&st=2016-11-10T14%3A05%3A41Z&se=2016-11-10T14%3A16%3A41Z&sp=r

我该如何解决这个问题?

【问题讨论】:

  • 您在上面提到的两个 SAS URL 中,您能分辨出哪个有效吗?
  • 第二个,我会添加到问题中

标签: java azure azure-blob-storage azure-java-sdk


【解决方案1】:

只需查看 SAS 令牌,您就可以使用文件名指定策略。这可能不是您想要做的,并且不在 .NET SAS 令牌中。

我猜问题出在这里:

blob.generateSharedAccessSignature(policy, externalFileName);

如果 API 类似于 .NET,则第二个参数可能是策略名称。

试试这个:

blob.generateSharedAccessSignature(policy, null);

【讨论】:

  • 谢谢,这就是问题所在。
猜你喜欢
  • 1970-01-01
  • 2013-03-17
  • 2015-03-01
  • 2015-07-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多