gpt4 book ai didi

java - 使用java SDK向blob添加标签

转载 作者:行者123 更新时间:2023-12-03 00:38:09 26 4
gpt4 key购买 nike

我正在尝试使用 java SDK 将索引标签添加到 azure Blob 存储上的数据。我需要添加标签,以便可以更轻松地进行过滤并实现生命周期策略。当我上传文件时,我希望为该文件添加映射值 y 的标签键 x 。我找不到任何有用的java文档,我发现的最接近的是this在 C# 中。另外,我确实找到了函数 setTags ( this too )看起来它可以满足我的要求,但我无法使其正常工作(该文件似乎是在没有标签的情况下上传的)。我尝试过以下代码:

String connectStr = System.getenv("AZURE_STORAGE_CONNECTION_STRING");
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder().connectionString(connectStr).buildClient();
BlobContainerClient container = blobServiceClient.getBlobContainerClient("tcpblobstorage");
BlobClient blobClient = container.getBlobClient(path + fileName);
Map<String, String> map = new HashMap<>();
map.put("Client", "Client");
blobClient.setTags(map);
blobClient.upload(is, length, true);

注意:path + fileName 是将要上传到 azure 的新文件的路径。

有人对我可能做错的事情有任何指示或想法吗?

最佳答案

我已经接受了@Gaurav 的回答,但如果有人来寻找它,这里是更新的代码:

String connectStr = System.getenv("AZURE_STORAGE_CONNECTION_STRING");
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder().connectionString(connectStr).buildClient();
BlobContainerClient container = blobServiceClient.getBlobContainerClient("tcpblobstorage");
BlobClient blobClient = container.getBlobClient(path + fileName);
Map<String, String> map = new HashMap<>();
map.put("Client", "Client");
BlockBlobSimpleUploadOptions options = new BlockBlobSimpleUploadOptions(is, length).setTags(map);
blobClient.getBlockBlobClient().uploadWithResponse(options, Duration.ofSeconds(30L), Context.NONE);

关于java - 使用java SDK向blob添加标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68441210/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com