尽管调用了 SetMetadataAsync() 然后调用了 UploadBlobAsync(),但在 blob 中未找到任何元数据或标记
Despite calling SetMetadataAsync() and then UploadBlobAsync() no metadata or tags is found in the blob
在我的 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,但元数据不存在:
我还尝试检索存储帐户的 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))
您实际上是在为 blob container
而不是 blob itself
设置元数据,因为您使用的是基于 blob container object
.[=15 的 SetMetadataAsync
方法=]
如果您想在上传过程中为 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);
}
在我的 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,但元数据不存在:
我还尝试检索存储帐户的 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))
您实际上是在为 blob container
而不是 blob itself
设置元数据,因为您使用的是基于 blob container object
.[=15 的 SetMetadataAsync
方法=]
如果您想在上传过程中为 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);
}