Reputation: 18799
So I am copying a blob blob
and overwriting another blob newBlob
with the following code:
CopyStatus copy = CopyStatus.Pending;
while (copy != CopyStatus.Success)
{
newBlob.StartCopyFromBlob(blob);
copy = manager.CheckIsDoneCopying(newBlob, container.Name);
}
newBlob
already has metadata on it before the copy and from here I see that:
If no name-value pairs are specified, the operation will copy the source blob metadata to the destination blob. If one or more name-value pairs are specified, the destination blob is created with the specified metadata, and metadata is not copied from the source blob.
which I gather means the old blobs metadata will not be copied over. I would like to force the original blob to overwrite newBlob's
metadata and then edit newBlobs metadata using the following:
newBlob.FetchAttributes();
if (newBlob.Metadata.ContainsKey(StorageManager.IsLive))
{
newBlob.Metadata[StorageManager.IsLive] = "Y";
}
else
{
newBlob.Metadata.Add(new KeyValuePair<string, string>(StorageManager.IsLive, "Y"));
}
if (newBlob.Metadata.ContainsKey(StorageManager.LastUploadedTime))
{
newBlob.Metadata[StorageManager.LastUploadedTime] = uploadedTime.Ticks.ToString();
}
else
{
newBlob.Metadata.Add(new KeyValuePair<string, string>(StorageManager.LastUploadedTime, uploadedTime.Ticks.ToString()));
}
Is it possible to force an overwrite of newblobs metadata from the old blob?
EDIT
If I add a line to my code:
CopyStatus copy = CopyStatus.Pending;
newBlob.Metadata.Clear();
while (copy != CopyStatus.Success)
{...
The metadata is copied over. Though this cannot be the only way as if the copy operation fails or never finishes this means I have an invalid newBlob. There must be a better way than this?
Upvotes: 0
Views: 653
Reputation: 6467
No, calling newBlob.Metadata.Clear() before executing newBlob.StartCopyFromBlob(blob) doesn't mean clearing newBlob's metadata at server side and then start asynchronously blob copying. To be clear, newBlob.Metadata.Clear() won't trigger a real request to server unless you call newBlob.SetMetadata() then.
Actually, calling newBlob.Metadata.Clear() before executing newBlob.StartCopyFromBlob(blob) just exactly means "not specifying any key-value pair in CopyBlob request", which is mentioned by what you saw from the MSDN webpage.
Therefore, your solution is just the perfect one as you expect, please verify it again! :)
Upvotes: 1