I want to generate a Presigned URL /SAS so that anyone with that url can access my file.
SDK Version : 12.8.0
I wrote the foll code :
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);
But the code throws error as
java.lang.NullPointerException: The argument must not be null or an empty string. Argument name: storageSharedKeyCredentials.
Edit 1 : Tried with :
UserDelegationKey userDelegationKey = blobServiceClient.getUserDelegationKey(keyStart,keyExpiry);
String blobUrl = Utility.urlDecode(blobClient.getBlobUrl());
blobUrl = blobUrl + "?" + blobClient.generateUserDelegationSas(blobServiceSasSignatureValues,userDelegationKey);
But now getting :
"Status code 403, "AuthenticationFailed
Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.\nRequestId:7b0f0d75-d01e-00a8-4d84-7c9aa3000000\nTime:2021-07-19T09:54:31.1312999ZThe specified signed resource is not allowed for the this resource level"",
storageSharedKeyCredentials
to sign your SAS. – Gaurav Mantri