</Message>AuthenticationErrorDetail>Signature did not match. string to sign used was w

236 Views Asked by At

I am trying to upload the file from local to azure blob storage using Azure blob storage dependency in Java Spring.

Here I’m using sas token to upload the file. The code snippet is:-

BlobClient blobClient=new BlobClientBuilder().endpoint(sasTokenUri).blobName(blobName).buildClient();
blobClient.uploadFromFile(“File”);

Here sasTokenUri = https://domain.blob.core.windows.net/containerName/?sv=2022-11-02&se=2023-10-17To4%3A29%3A52z&sr=d&sp=w&sdd=1&sig=xxxxxxxxxxxx

Could anyone please help to identify the issue and resolve it?

1

There are 1 best solutions below

2
Venkatesan On BEST ANSWER

Local to azure blob storage using Azure blob storage

The above error occurs when you pass the wrong sas token in your code.

You can get the SAS token from the portal.

Portal:

Storageaccounts-> shared access signature -> check the required fields -> Generate SAS-token.

enter image description here

Now, I tried with the below code it successfully executed and uploaded file from local to Azure blob storage,

Code:

String sasToken = "?sv=2022-11-02&ss=bfqt&srt=sco&sp=rwdlacupiytfx&se=2023-10-17T13:32:35Z&st=2023-10-17T05:32:35Z&spr=https&sig=xxxxx";
String sasTokenUri="https://venkat123.blob.core.windows.net/test/" + sasToken;
String blobName = "sample.png";
String filePath = "Your local path";

BlobClientBuilder builder = new BlobClientBuilder().endpoint(sasTokenUri).blobName(blobName);
        builder.buildClient().uploadFromFile(filePath);
System.out.println("The file is uploaded successfully.");

Output: enter image description here

Portal: enter image description here

Reference: Azure Storage Blob client library for Java | Microsoft Learn