How to upload a file to azure storage as a filestream using C#

I’ll try to make it as simple as possible:

StorageCredentials myCreds = new
StorageCredentials(“NAME OF YOUR BLOB”, “THE KEY YOU GET FROM AZURE”);


CloudBlobClient myClient = new
CloudBlobClient(new
Uri(http://YOURBLOB’S NAME.blob.core.windows.net/”),myCreds);


CloudBlobContainer cont = myClient.GetContainerReference(“CONTAINER NAME”);


var blockBlob = cont.GetBlockBlobReference(“file1.csv”);


var nStream = new
MemoryStream(filecontents);

 

blockBlob.UploadFromStream(nStream);

That’s it!

Things you will need:

using Microsoft.WindowsAzure.Storage;

using Microsoft.WindowsAzure.Storage.Auth;

using Microsoft.WindowsAzure.Storage.Blob;

comes from:

When you add that as a reference

And of course a blob.

 

Advertisements
This entry was posted in Computers and Internet. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s