I am trying to use java SDK in order to connect to Azure Blob. On the method create if not exists I constantly get a general error.
StorageCredentials storageCredentials = new StorageCredentialsAccountAndKey(getShareAccount(), Base64.encode(getShareKey().getBytes()));
CloudStorageAccount storageAccount = new CloudStorageAccount(storageCredentials, true);
CloudBlobClient c = storageAccount.createCloudBlobClient();
CloudBlobContainer container = c.getContainerReference(containerName);
container.createIfNotExists();
i get the following error Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
when I try to
container.create();
I receive: Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. RequestId:.... Time:2024-02-09T09:16:26.4410074Z
I tried to change my local machine time to GMT, but the error persists. My Azure blob is in eastus2, tried to change my local machine time to that timezone but it did not work.
Do you know what is the problem?
To create a
containerin Azure blob storage you can use the below java code.Code:
The above code creates a new Azure Blob Storage container using the Azure Storage Blob SDK for Java. It first creates a
BlobServiceClientobject using theconnection stringof your storage account and then creates a new container with the specified name using thecreateBlobContainermethod of theBlobServiceClientobject. The code then prints a message to the console indicating that the container has been created.Pom.xml
Output:
Portal:
Reference:
Quickstart: Azure Blob Storage library - Java | Microsoft Learn