Hello,
I am trying to generate a URL link to download the file uploaded to my container. I was able to generate the URL but when I used that URL it gave the following error.
<Error>
<Code>AuthenticationFailed</Code>
<Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. </Message>
<AuthenticationErrorDetail>Signature did not match.</AuthenticationErrorDetail>
</Error>
I am using the following code to generate the SAS token.
BlobContainerSasPermission blobContainerSasPermission = new BlobContainerSasPermission()
.setReadPermission(true)
BlobServiceSasSignatureValues builder = new BlobServiceSasSignatureValues(OffsetDateTime.now().plusDays(1), blobContainerSasPermission)
.setProtocol(SasProtocol.HTTPS_ONLY);
BlobClient client = new BlobClientBuilder()
.connectionString("connection string")
.blobName("")
.buildClient();
String blobContainerName = "test";
return String.format("https://%s.blob.core.windows.net/%s?%s",client.getAccountName(), blobContainerName, client.generateSas(builder));
I also tried to use the following code to generate the SAS token:-
CloudStorageAccount account = CloudStorageAccount.parse(blobConnectionString);
// Create a blob service client
CloudBlobClient blobClient = account.createCloudBlobClient();
CloudBlobContainer container = blobClient.getContainerReference(containerName);
Date expirationTime = Date.from(LocalDateTime.now().plusDays(7).atZone(ZoneOffset.UTC).toInstant());
SharedAccessBlobPolicy sharedAccessPolicy=new SharedAccessBlobPolicy();
sharedAccessPolicy.setPermissions(EnumSet.of(SharedAccessBlobPermissions.READ,
SharedAccessBlobPermissions.WRITE,SharedAccessBlobPermissions.ADD));
sharedAccessPolicy.setSharedAccessStartTime(new Date());
sharedAccessPolicy.setSharedAccessExpiryTime(expirationTime);
String sasToken = container.generateSharedAccessSignature(sharedAccessPolicy, null);
But I got the same error everytime.
I went through all the solutions which I came across, but nothing seems to work. It would be great to receive some suggestions.