Anatoly
Anatoly

Reputation: 1916

How to correctly UploadAsync to Azure page blob?

That's how I upload to azure page blob storage

var memoryStream = new MemoryStream(range, offsetToTransfer, sizeToTransfer, false, false);
pageBlob.WritePages(memoryStream, vhdOffset + offsetToTransfer, null);
Console.WriteLine("Range ~" + Megabytes(offsetToTransfer + vhdOffset) + " + " + PrintSize(sizeToTransfer));`

Azure recommend me to use this library to upload etc.

How can I set second parameter (it's offset) vhdOffset + offsetToTransfer to UploadAsync? I mean how can I specify a position where I want to write?

var memoryStream = new MemoryStream(range, offsetToTransfer, sizeToTransfer, false, false);
TransferManager.UploadAsync(memoryStream, pageBlob);

Upvotes: 0

Views: 800

Answers (1)

stephgou
stephgou

Reputation: 199

If you wish to write a page with an offset, you may use the CloudPageBlob.WritePagesAsync API wich is documented here. https://msdn.microsoft.com/en-us/library/microsoft.windowsazure.storage.blob.cloudpageblob.writepagesasync(v=azure.10).aspx

There a complete sample based on CloudPageBlob.WritePages API here.

https://blogs.msdn.microsoft.com/windowsazurestorage/2010/04/10/using-windows-azure-page-blobs-and-how-to-efficiently-upload-and-download-page-blobs/

The following code :

    MemoryStream memoryStream = new MemoryStream(range, 
                       offsetToTransfer, sizeToTransfer, false, false);
    pageBlob.WritePages(memoryStream, vhdOffset + offsetToTransfer);

allows you to write a sequential set of pages up to 4MBs, and the offset being written to must start on a 512 byte boundary (startingOffset % 512 == 0), and end on a 512 boundary – 1.

Hope this helps

Best regards

Stéphane

Upvotes: 1

Related Questions