Azure Storage Blobs: what kind of blob do I get with GetBlobReference()?

vtortola picture vtortola · Feb 4, 2011 · Viewed 8.4k times · Source

I'm getting a little confused with blobs. I've read some articles that says that there are two kinds of blobs, blocks and pages, but I can see in the SDK's library a third one:

container.GetBlockBlobReference(); // Block Blob, max 64Mb per block,  max 200Gb in total.
container.GetPageBlobReference(); // Page Blob, aligned to 512bytes pages,  max 1Tb in total.
container.GetBlobReference(); // ??

Is CloudBlob a CloudBlockBlob or a CloudPageBlock? Which constrains applies? Do I have to worry about file size and put blocks or pages when I use that reference?

I've been reading MSDN but I cannot find which one is.

Answer

user94559 picture user94559 · Feb 4, 2011

GetBlobReference returns you a CloudBlob object. That can represent either kind of blob. The .ToPageBlob and .ToBlockBlob properties will aid in casting the object, but that has nothing to do with the type of the blob that exists. The blob that exists is of one type or the other, specified when you create it.

If you call .Create on a CloudPageBlob object, that will result in a page blob being created in Windows Azure.

If you call .UploadText() on a BlockBlobObject (or a generic CloudBlob object), that will result in a block blob being created in Windows Azure.

In other words, GetBlobReference returns you a generic reference to a blob (not to either type).