1
votes

I want to change my blob type from Append Blob to BlockBlob. According to How to convert from Azure Append Blob to Azure Block Blob This is not possible. I, therefore, want to make a copy

            var container = blobClient.GetContainerReference("videos");
            var sourceBlob = container.GetAppendBlobReference(blobName);
            var newBlobName = blobName + "FinalBlob";
            var targetBlob = container.GetBlobReference(newBlobName);

            targetBlob.StartCopyAsync(sourceBlob.Uri).Wait();

The resulting blob is an Appendblob, not BlockBlob

2
I am not sure but maybe give it a try - instead of GetBlobReference(newBlobName) use GetBlockBlobReference(newBlobName)majewka

2 Answers

1
votes

It is not possible to change the blob type through copy operation. Destination blob's type will always be the same as source blob's type.

Two possible solutions I could think of:

  • Download & Upload: As mentioned in my other answer, you could download the append blob to your local machine and then upload it again as block blob.
  • Copy To File Share & Copy Back: Other solution could be to copy the blob to a file share first. Once the copy operation is complete, you can copy that file back to blob storage. In this case, the blob type of the copied blob will always be Block Blob.
-1
votes

The copy commands work just fine:


    foreach (var blob in container.ListBlobs(input.OutputPrefix + "/", true).OfType<CloudAppendBlob>())
    {
        var test = container.GetBlockBlobReference(blob.Name.Replace(".csv", "out.csv"));
        await test.StartCopyAsync(new Uri(blob.Uri+blob.GetSharedAccessSignature(new SharedAccessBlobPolicy { Permissions= SharedAccessBlobPermissions.Read, SharedAccessExpiryTime= DateTimeOffset.UtcNow.AddHours(2) })));
    }

Above code has been testet and works.