简体   繁体   English

使用 spring boot 在 azure 中从 v8 升级到 v12 java sdk 后无法连接到 azure-blob-storage

[英]Unable to connect to azure-blob-storage after upgrading from v8 to v12 java sdk in azure using spring boot

I am upgrading my existing spring boot application which uses azure-blob-storage from V8 SDK to V12 SDK.我正在将使用 azure-blob-storage 的现有 Spring Boot 应用程序从 V8 SDK 升级到 V12 SDK。 But I am getting authorization error.但我收到授权错误。 I almost tried all the examples suggested in azure sdk, but none of them are working.我几乎尝试了 azure sdk 中建议的所有示例,但它们都不起作用。 Below is the code between v8 and v12.下面是 v8 和 v12 之间的代码。

V8 (Working fine): V8(工作正常):

String endPoint = https://XXXXXXX.blob.core.windows.net/ecommerce/
String sasToken = sp=racwl&st=2021-06-01T05:12:04Z&se=2026-06-01T13:12:04Z&spr=https&sv=2020-02-05&sr=c&sig=XXXXXX%2BXXXXXXXXXXX%2BVVVVVVVVVVVV%3D
StorageCredentialsSharedAccessSignature s = new StorageCredentialsSharedAccessSignature("sas_token");
CloudBlobContainer cbc = new CloudBlobContainer(s.transformUri(new URI(endPoint)));

CloudBlobDirectory bd = cbc.getDirectoryReference("container_name");
InputStream is = new ByteArrayInputStream("my_string".getBytes());
CloudBlockBlob cbb = bd.getBlockBlobReference("blob_name");
cbb.upload(is, "my_string".length());

V12 (Failing with authentication): V12(身份验证失败):


String endPoint = https://XXXXXXX.blob.core.windows.net/ecommerce/
String sasToken = sp=racwl&st=2021-06-01T05:12:04Z&se=2026-06-01T13:12:04Z&spr=https&sv=2020-02-05&sr=c&sig=XXXXXX%2BXXXXXXXXXXX%2BVVVVVVVVVVVV%3D
BlobContainerClient bc = new BlobContainerClientBuilder().endpoint(endPoint).sasToken(sasToken).containerName("container_name").buildClient();
InputStream targetStream = new ByteArrayInputStream("my_string".getBytes());
BlockBlobClient cbb = bc.getBlobClient("blob_name").getBlockBlobClient();
cbb.upload(targetStream, payload.length()); ----> This is where it is throwing the exception

Error with V12 approach failing at authentication: V12 方法在身份验证失败时出错:

com.azure.storage.blob.models.BlobStorageException: If you are using a StorageSharedKeyCredential, and the server returned an error message that says 'Signature did not match', you can compare the string to sign with the one generated by the SDK. To log the string to sign, pass in the context key value pair 'Azure-Storage-Log-String-To-Sign': true to the appropriate method call.
If you are using a SAS token, and the server returned an error message that says 'Signature did not match', you can compare the string to sign with the one generated by the SDK. To log the string to sign, pass in the context key value pair 'Azure-Storage-Log-String-To-Sign': true to the appropriate generateSas method call.
Please remember to disable 'Azure-Storage-Log-String-To-Sign' before going to production as this string can potentially contain PII.
Status code 403, (empty body)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    ...

I was able to connect successfully now with the below code.我现在可以使用以下代码成功连接。 However, there is still an issue with the actuator/health page但是,执行器/健康页面仍然存在问题

BlobContainerClient bcc = new BlobContainerClientBuilder().endpoint(reportProperties.getEndpoint() + "/" + containerName + "/" + "?" + reportProperties.getSastoken()).buildClient();
BlobClient blobClient = bcc.getBlobClient(blobName);
InputStream is = new ByteArrayInputStream("my_string".getBytes());
blobClient.upload(is, payload.length());

After a days work this is how I managed to get this to work with SDK V12.14.1:经过一天的工作,这就是我设法让它与 SDK V12.14.1 一起使用的方法:

    String endpoint = String.format(Locale.ROOT,
            "https://%s.blob.core.windows.net", "myStorage");
    
    AzureSasCredential sasCredential = new AzureSasCredential(
            "sp=racwdl&st=2021-10-21T12:23:00Z&se=2021-10-21T20:23:00Z&spr=https&sv=2020-08-04&sr=c&sig=vV...MI%3D");

    BlobServiceClient blobServiceClient = new BlobServiceClientBuilder()
            .endpoint(endpoint).credential(sasCredential).buildClient();

    BlobContainerClient blobContainerClient = blobServiceClient
            .getBlobContainerClient("myContainer");
    for (BlobItem blobItem : blobContainerClient.listBlobs()) {
        BlockBlobClient blobClient = blobContainerClient
                .getBlobClient(blobItem.getName()).getBlockBlobClient();
        System.out.println(blobClient.getBlobName());
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Java v12 SDK 在 Azure Blob 存储中复制 Blob - Copy Blob in Azure Blob Storage using Java v12 SDK 如何使用 Azure.Storage v12 SDK 从 Azure Blob 中删除元数据? - How can I remove metadata from an Azure Blob using Azure.Storage v12 SDK? 如何使用新的 Java v12 SDK 为 Azure Blob 存储检索分段的容器列表? - How to retrieve a segmented List of Containers using the new Java v12 SDK for Azure Blob Storage? Azure Blob 存储 SDK v12 - BlobClient DownloadAsync 消失了吗? - Azure Blob Storage SDK v12 - BlobClient DownloadAsync gone? 如何使用新的 Azure 存储 SDK v12 打开可写 ZF7B44CFFAFD5C52223D5498196C8A2E7BZ 到新 Blob? - How can I open a writeable stream to a new Blob using the new Azure Storage SDK v12? 使用带有 Python V12 SDK 的 BlobServiceClient 将本地文件夹上传到 Azure Blob 存储 - Upload local folder to Azure Blob Storage using BlobServiceClient with Python V12 SDK 如何使用 .NET v12 SDK 在 Azure Blob 存储中使用指定的 ContentType 上传 Blob? - How upload blob in Azure Blob Storage with specified ContentType with .NET v12 SDK? 使用指定的 ContentType 将 blob 上传到 Azure Blob 存储并同时覆盖(.NET v12 SDK)? - Upload blob into Azure Blob Storage with specified ContentType and overwrite same time (.NET v12 SDK)? ContentHash 未在 Azure Blob Storage v12 中计算 - ContentHash not calculated in Azure Blob Storage v12 如何从适用于 Node.js 的 Azure blob v12 SDK 中删除 blob - How to Delete a blob from Azure blob v12 SDK for Node.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM