java - 天青java : SAS identifier cannot be found for specified signed identifier

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

我正在使用 Java SDK 创建 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(有效)与我在这里得到的 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 token ,您就可以使用文件名指定策略。这可能不是您想要做的,并且不在 .NET SAS token 中。

我猜问题就在这里:

blob.generateSharedAccessSignature(policy, externalFileName);

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

试试这个:

blob.generateSharedAccessSignature(policy, null);

关于java - 天青java : SAS identifier cannot be found for specified signed identifier,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40529605/

相关文章:

amazon-web-services - Azure 应用服务与 AWS SES 的通信

node.js - 使用nodejs将数据从Rfid rc522发送到azure iot hub

azure - 运行命令扩展正在执行。请等待完成后再调用运行命令

c# - 获取上传的 blob 的 URI?

c# - 调用 CloudBlobContainer.GetBlockBlobReference 是否会进行任何网络通信?

java - SQLite 数据库的 RuntimeException - Android

java - 为什么覆盖 equals 不适用于在 Map 中添加相同的对象?

java - 在 Linux 中杀死 Java 线程

java - 在 Android 上更改 Google map 中的标记

excel - 我的 VBA 代码未将 csv 文件上传到 Azure 中的 ADLS