gpt4 book ai didi

azure - 尽管调用 SetMetadataAsync() 和 UploadBlobAsync(),但在 blob 中找不到元数据或标签

转载 作者:行者123 更新时间:2023-12-03 05:32:12 27 4
gpt4 key购买 nike

在我的 SF 应用程序中,我调用以下 C# 代码:

private readonly BlobContainerClient containerClient = null;
private readonly IDictionary<string, string> metadata = new Dictionary<string, string>();

DateTime now = DateTime.Now;
this.metadata.Clear();
this.metadata.Add("tag1", blobBasicName);
blobName = string.Format("{0}/{1:00}_{2:00}_{3:00}/{4:00}_{5:00}_{6:00}",
blobBasicName, now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second);

using (MemoryStream ms = new MemoryStream(objectToWriteToBlob))
{
await this.containerClient.SetMetadataAsync(metadata);
await this.containerClient.UploadBlobAsync(blobName, ms);
}

并且可以在 Azure 门户中看到上传的 blob,但元数据不存在:

azure screenshot

我还尝试检索存储帐户的 blob 列表,但 blob.tags 也没有在那里设置:

container_client = ContainerClient.from_connection_string(conn_str, container_name=container_name)

blob_list = []
print('Fetching blobs from %s...' % container_name)
for blob in container_client.list_blobs():
if blob.name.startswith(MY_BLOB_PREFIX) and blob.size > 500:
print('blob name = %s, tags = %s' % (blob.name, blob.tags))
blob_list.append(blob)
print('Fetched %d non-empty blobs from %s' % (len(blob_list), container_name))

cmd screenshot

最佳答案

您实际上是在为 blob 容器 设置元数据,而不是为 blob 本身,因为您使用的 SetMetadataAsync 方法基于blob 容器对象

如果您想在上传过程中为 blob 设置元数据,应使用以下代码:

private readonly BlobContainerClient containerClient = null;
private readonly IDictionary<string, string> metadata = new Dictionary<string, string>();

DateTime now = DateTime.Now;
this.metadata.Clear();
this.metadata.Add("tag1", blobBasicName);
blobName = string.Format("{0}/{1:00}_{2:00}_{3:00}/{4:00}_{5:00}_{6:00}",
blobBasicName, now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second);

var blobclient = containerClient.GetBlobClient(blobName);


using (MemoryStream ms = new MemoryStream(objectToWriteToBlob))
{
blobclient.Upload(ms, null, metadata, null, null, null);
}

关于azure - 尽管调用 SetMetadataAsync() 和 UploadBlobAsync(),但在 blob 中找不到元数据或标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64595194/

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