Read file from Azure blob storage

Hope picture Hope · Jun 13, 2012 · Viewed 24.9k times · Source

I want to read a PDF file bytes from azure storage, for that I have a file path.

https://hostedPath/pdf/1001_12_Jun_2012_18_39_05_594.pdf

So it possible to read content from blob storage by directly passing its Path name? Also I am using c#.

Answer

David Makogon picture David Makogon · Jun 13, 2012

As long as the blob is public, you can absolutely pass the blob url. For instance, you can embed it in an html image or link:

<a href="https://myaccount.blob.core.windows.net/pdf/1001_12_Jun_2012_18_39_05_594.pdf">click here</a>

By default, blob containers are private. To enable public read access, you just have to change the container permissions when creating the container. For instance:

var blobStorageClient = storageAccount.CreateCloudBlobClient();
var container = blobStorageClient.GetContainerReference("pdf");
container.CreateIfNotExist();

var permissions = container.GetPermissions();
permissions.PublicAccess = BlobContainerPublicAccessType.Container;
container.SetPermissions(permissions);