I used to initiate copy blob and while copying was in progress we were able to read few bytes (e.g. first 512 bytes) of the destination blob. See below code that initiate copy blob and then read the first 512 bytes while copying is in progress.
But now blobStream.Read always fills the data buffer with zero not with the actual bytes. I have tried with latest azure storage client lib also, but output is same. But as soon as the copy finishes I can read the actual bytes.
Someone please let me know whether this is a bug introduced in the latest azure storage service and possible workaround (if any)?
CloudBlobClient client = CloudStorageAccount.Parse(
string.Format(
"DefaultEndpointsProtocol={0};AccountName={1};AccountKey={2}",
"http",
"<destination-account-name>",
"<destination-account-key>"
)
).CreateCloudBlobClient();
var vhdsContainer = client.GetContainerReference("<destination-container-name>");
CloudBlob destinationBlob = vhdsContainer.GetPageBlobReference("test-1-b5c1d3f4-23d5-40e4-adc7-236553f8d62d-1.vhd");
destinationBlob.StartCopyFromBlob(
new Uri("http://<source-storage>.blob.core.windows.net/<source-container-name>/test-4-d803ca0a-5d98-4be8-8895-2a9d15ec3974-1.vhd"), null, null, null);
CloudBlob destBlob = vhdsContainer.GetBlobReference("test-1-b5c1d3f4-23d5-40e4-adc7-236553f8d62d-1.vhd");
int maxWaitTime = 3*60000;//let's wait for a maximum of 3 minute
do
{
destBlob.FetchAttributes();
if (destBlob.CopyState.BytesCopied > 2048 || maxWaitTime <= 0)
{
break;
}
maxWaitTime -= 1000;
Thread.Sleep(1000);
}
while (true);
var data = new byte[512];
using (BlobStream blobStream = destBlob.OpenRead())
{
blobStream.Seek(0, System.IO.SeekOrigin.Begin);
blobStream.Read(data, 0, 512);
}