Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect Azure Storage to read .txt files from blob storage

Could anyone let me know how to read a text file from Azure Blob Storage?

like image 702
SRA Avatar asked Nov 11 '10 05:11

SRA


People also ask

How do I view a text file in an Azure storage container?

Go to Container from the portal and select the particular file to get the link to access. Copy the link and paste in the Browser. Here are your files. Hence, from the steps shown above, you can create Storage account, Container, store and access the files from the portal.

How do you read data from Azure blob storage?

Open the File Selector dialog from the Message Analyzer File menu by highlighting Open and then selecting the From Other File Sources command. In the Add Azure Storage Connection dialog, specify Account name and Account key information, as described in Accessing Log Data in Azure Storage BLOB Containers.

How do I access files from blob storage?

Open a blob on your local computer Select the blob you wish to open. On the main pane's toolbar, select Open. The blob will be downloaded and opened using the application associated with the blob's underlying file type.

How do I connect to Azure storage blob?

Under the search box, select Built-in. In the search box, enter Azure blob. From the Triggers list, select the built-in trigger named When a blob is Added or Modified in Azure Storage. If you're prompted for connection details, create a connection to your Azure Storage account.


2 Answers

It's pretty easy:

string text = CloudStorageAccount.Parse("<your connection string>").CreateCloudBlobClient().GetBlobReference("path/to/the/blob.txt").DownloadText();

Of course, if the blob is in a public container, you can just do:

string text = new WebClient().DownloadString("http://youraccount.blob.core.windows.net/path/to/blob.txt");
like image 79
user94559 Avatar answered Sep 30 '22 04:09

user94559


// connect to development storage. To connect to azure storage use connection string
CloudStorageAccount storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
CloudBlobClient client = storageAccount.CreateCloudBlobClient();

// if you know the blob you want to access you can do this:
CloudBlob blob = client.GetBlobReference("containername/blobname.txt");

// To display text in console:
Console.WriteLine(blob.DownloadText());
Console.ReadKey();
like image 20
crunchy Avatar answered Sep 30 '22 06:09

crunchy