我想生成一个预签名 URL /SAS,以便拥有该 URL 的任何人都可以访问我的文件。
SDK版本:12.8.0
我写了以下代码:
BlockBlobClient blockBlobClient = objectStoreService.getBlobContainerClient().getBlobClient(fileName).getBlockBlobClient();
String blobUrl = Utility.urlDecode(blockBlobClient.getBlobUrl());
BlobSasPermission blobPermission = new BlobSasPermission()
.setReadPermission(true);
BlobServiceSasSignatureValues blobServiceSasSignatureValues = new BlobServiceSasSignatureValues(
OffsetDateTime.now(ZoneOffset.UTC).plusSeconds(1000 * 60 * 60),
blobPermission
);
blobUrl = blobUrl + "?" + blockBlobClient.generateSas(blobServiceSasSignatureValues);
但代码抛出错误
java.lang.NullPointerException:参数不能为 null 或空字符串。参数名称:storageSharedKeyCredentials。
编辑1:尝试过:
UserDelegationKey userDelegationKey = blobServiceClient.getUserDelegationKey(keyStart,keyExpiry);
String blobUrl = Utility.urlDecode(blobClient.getBlobUrl());
blobUrl = blobUrl + "?" + blobClient.generateUserDelegationSas(blobServiceSasSignatureValues,userDelegationKey);
但现在得到:
“状态码 403,”AuthenticationFailed
服务器无法验证请求。确保 Authorization 标头的值格式正确,包括签名。\nRequestId:7b0f0d75-d01e-00a8-4d84-7c9aa3000000\nTime:2021-07-19T09:54:31.1312999Z此资源级别不允许指定的已签名资源"",