azure blobs java sdk无法返回对象的版本ID列表

oaxa6hgo  于 2021-07-09  发布在  Java
关注(0)|答案(1)|浏览(572)

我试图通过JavaSDK版本12.10.2获取azure blob的versionID列表,但它只返回http错误400和以下错误消息

com.azure.storage.blob.models.BlobStorageException: Status code 400, "<?xml version="1.0" encoding="utf-8"?><Error><Code>InvalidQueryParameterValue</Code><Message>Value for one of the query parameters specified in the request URI is invalid.
RequestId:bd7e9a20-401e-003e-6d7b-37d0dd000000
Time:2021-04-22T13:29:12.0965760Z</Message><QueryParameterName>include</QueryParameterName><QueryParameterValue>versions</QueryParameterValue><Reason>Invalid query parameter value.</Reason></Error>"

这是我的java代码:

public static BlobContainerAsyncClient getAzureAsyncClient(String accountName, String accountKey, String endpoint) {
        String connectionString = getConnectionString(accountName, accountKey, endpoint);
        BlobContainerAsyncClient blobServiceClient = new BlobContainerClientBuilder()
          .connectionString(connectionString)
          .serviceVersion(version)
                  .buildAsyncClient();
    RWLog.MAIN.info("Azure Storage Async Service Client created for " + accountName);    
        return blobServiceClient;
}

BlobContainerAsyncClient containerClient = AzureConnection.getAzureAsyncClient(folder.getBucket(), folder.getSecretKey(), folder.getEndpoint());
    ListBlobsOptions ops = new ListBlobsOptions();
    ops.getDetails().setRetrieveVersions(true);
    ops.setPrefix(blobKey);
    PagedFlux<BlobItem> list =
        containerClient.listBlobsByHierarchy("/", ops);

azureblobs服务器似乎无法识别由javasdk构造的http请求。服务器端无法处理来自java客户端的包含版本的查询。有什么想法吗?

eblbsuwk

eblbsuwk1#

使用12.10.2的 azure-storage-blob 要获取blob的所有版本,请执行以下操作:

public static void main(String[] args) {

                String connString = "";
                String containerName = "";
                String blobName = "";

                BlobServiceClient client = new BlobServiceClientBuilder().connectionString(connString).buildClient();

                BlobContainerClient blobContainerClient = client.getBlobContainerClient(containerName);
                ListBlobsOptions options = new ListBlobsOptions().setPrefix(blobName)
                                .setDetails(new BlobListDetails().setRetrieveVersions(true));

                Iterator<BlobItem> it = blobContainerClient.listBlobs(options, null).iterator();
                while (it.hasNext()) {
                        BlobItem item = it.next();
                        System.out.println(" versionID: " + item.getVersionId());
                }

        }

结果:


相关问题