Azure blob API 返回确保授权标头的值格式正确,包括向其上传文件时的签名

问题描述 投票:0回答:1

我正在尝试使用 java SDK 来连接到 Azure Blob。在 create if not exits 方法上,我不断收到一般错误。

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();

我收到以下错误 服务器无法验证请求。确保授权标头的值正确形成,包括签名。

当我尝试

container.create();

我收到: 服务器无法验证请求。确保授权标头的值格式正确,包括签名。 请求ID:.... 时间:2024-02-09T09:16:26.4410074Z

我尝试将本地计算机时间更改为 GMT,但错误仍然存在。我的 Azure blob 位于 eastus2,尝试将我的本地计算机时间更改为该时区,但没有成功。

你知道问题出在哪里吗?

azure azure-blob-storage azure-java-sdk azure-java-tools
1个回答
0
投票

我尝试将本地计算机时间更改为 GMT,但错误仍然存在。我的 Azure blob 位于 eastus2,尝试将我的本地计算机时间更改为该时区,但没有成功。

你知道问题出在哪里吗?

要从 Azure Blob 存储创建

container
,您可以使用以下 Java 代码。

代码:

import com.azure.storage.blob.*;
import java.io.*;

public class App
{
    public static void main(String[] args) throws IOException
    {
        String connectStr="<Connection-string of your storage account>";
        BlobServiceClient blobServiceClient = new BlobServiceClientBuilder()
        .connectionString(connectStr)
        .buildClient();
        String containerName = "sample";
        BlobContainerClient blobContainerClient = blobServiceClient.createBlobContainer(containerName);
        System.out.println("The container is created!!!!");
    }
} 

上述代码使用适用于 Java 的 Azure 存储 Blob SDK 创建一个新的 Azure Blob 存储容器。它首先使用存储帐户的

BlobServiceClient
 创建一个 
connection string
对象,然后使用
createBlobContainer
对象的
BlobServiceClient
方法创建具有指定名称的新容器。然后,代码会向控制台打印一条消息,指示容器已创建。

Pom.xml

<dependency>
    <groupId>com.azure</groupId>
    <artifactId>azure-storage-blob</artifactId>
    <version>12.25.1</version>
</dependency>

输出:

 The container is created!!!!
 

enter image description here

传送门: enter image description here

参考:

快速入门:Azure Blob 存储库 - Java |微软学习

© www.soinside.com 2019 - 2024. All rights reserved.