Copy Azure Blob and its metadata

user1

So I would like to copy an Azure blob and its metadata to a new blob. I have the method

public void CopyBlob(CloudBlockBlob blob, CloudBlockBlob newBlob)
{
     CopyStatus copy = CopyStatus.Pending;
     while (copy != CopyStatus.Success)
     {
           newBlob.StartCopyFromBlob(blob);
           copy = CheckIsDoneCopying(newBlob, "MyContainerName");
     }
}

public CopyStatus CheckIsDoneCopying(CloudBlockBlob blob, string containerName)
{
    while (blob.CopyState.Status == CopyStatus.Pending)
    {
        Thread.Sleep(TimeSpan.FromSeconds(20));
        blob = GetBlob(blob.Name, containerName);
    }
    return blob.CopyState.Status;
}

These methods work fine for copying a blob but doesn't copy existing metadata from my existing blob to the new one. Is this possible?

Stopped Contributing

Looking at the REST API documentation for Copy Blob one thing caught my eye (Under Request Headers section, x-ms-meta-name:value):

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.

Now when I took a look at your source code, you're actually setting the metadata on the new blob before copying.

newBlob.FetchAttributes();
if (newBlob.Metadata.ContainsKey(StorageManager.IsLive))
{
    newBlob.Metadata[StorageManager.IsLive] = "N";
}
else
{
    newBlob.Metadata.Add(new KeyValuePair<string, string>(StorageManager.IsLive, "N"));
} 

Since metadata already exists for the new blob, the copy blob operation will not copy the metadata from source blob to the destination.

If you remove the code above, the metadata from source blob should be copied over to the new blob.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Setting and Retrieving metadata of blob in Azure Blob Storage

From Dev

Copy Azure Blob With Snapshots

From Dev

What is the maximum length of Azure blob metadata values?

From Dev

What is the maximum length of Azure blob metadata values?

From Dev

Nodejs Azure Storage Copy Blob to New Blob

From Dev

VSTS Copy File To Azure Blob

From Dev

Can't retrieve metadata for Blob in azure storage blob with java

From Dev

Is it possible to force azure blob metadata to be overwritten on new blob when copying

From Dev

How to copy an Azure File to an Azure Blob?

From Dev

Metadata fields not received from azure java sdk on a blob

From Dev

Azure Copy blob to different premium storage account

From Dev

Copy file from URL to Azure BLOB

From Dev

Azure Copy blob to different premium storage account

From Dev

Overwrite Blob But Keep Metadata?

From Dev

Copy From Azure Blob to AWS S3 Bucket

From Dev

Python: How to move or copy Azure Blob from one container to another

From Dev

Copy From Azure Blob to AWS S3 Bucket

From Dev

Copy blob from Azure storage account to a Network Path

From Dev

Azure Search invalid base64 path in metadata using Blob Storage Indexer

From Dev

I cannot update the metadata in the intranet site's html in the Azure blob container

From Dev

malloc storing its metadata

From Dev

FFmpeg Metadata does not copy

From Dev

Azure pipeline - unzip artefact, copy one directory into Azure blob store YAML file

From Dev

Use Azure Storage SDK for Java to copy VM page blob from one Azure subscription to another

From Dev

Azure Function(C#): How to copy lots of files from blob container A to another blob container B? (Function has timeout in 10 mins)

From Dev

Can I upload a stream to Azure blob storage without specifying its length upfront?

From Dev

How to automatically copy files when created in box.com to Azure blob storage?

From Dev

Where exactly is the "metadata" boundary in a JPEG raw blob?

From Dev

Comparing a float and its copy

Related Related

  1. 1

    Setting and Retrieving metadata of blob in Azure Blob Storage

  2. 2

    Copy Azure Blob With Snapshots

  3. 3

    What is the maximum length of Azure blob metadata values?

  4. 4

    What is the maximum length of Azure blob metadata values?

  5. 5

    Nodejs Azure Storage Copy Blob to New Blob

  6. 6

    VSTS Copy File To Azure Blob

  7. 7

    Can't retrieve metadata for Blob in azure storage blob with java

  8. 8

    Is it possible to force azure blob metadata to be overwritten on new blob when copying

  9. 9

    How to copy an Azure File to an Azure Blob?

  10. 10

    Metadata fields not received from azure java sdk on a blob

  11. 11

    Azure Copy blob to different premium storage account

  12. 12

    Copy file from URL to Azure BLOB

  13. 13

    Azure Copy blob to different premium storage account

  14. 14

    Overwrite Blob But Keep Metadata?

  15. 15

    Copy From Azure Blob to AWS S3 Bucket

  16. 16

    Python: How to move or copy Azure Blob from one container to another

  17. 17

    Copy From Azure Blob to AWS S3 Bucket

  18. 18

    Copy blob from Azure storage account to a Network Path

  19. 19

    Azure Search invalid base64 path in metadata using Blob Storage Indexer

  20. 20

    I cannot update the metadata in the intranet site's html in the Azure blob container

  21. 21

    malloc storing its metadata

  22. 22

    FFmpeg Metadata does not copy

  23. 23

    Azure pipeline - unzip artefact, copy one directory into Azure blob store YAML file

  24. 24

    Use Azure Storage SDK for Java to copy VM page blob from one Azure subscription to another

  25. 25

    Azure Function(C#): How to copy lots of files from blob container A to another blob container B? (Function has timeout in 10 mins)

  26. 26

    Can I upload a stream to Azure blob storage without specifying its length upfront?

  27. 27

    How to automatically copy files when created in box.com to Azure blob storage?

  28. 28

    Where exactly is the "metadata" boundary in a JPEG raw blob?

  29. 29

    Comparing a float and its copy

HotTag

Archive