Tuesday, August 13, 2019

Upload zip file to azure blob storage



    CloudStorageAccount storageAccount =   CloudStorageAccount.Parse("ConnectionString");
                // Create the blob client.
                CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

                // Retrieve reference to a previously created container.
                CloudBlobContainer container = blobClient.GetContainerReference("Container Name");

                FileInfo zipFile = new FileInfo(@"C:\Documents\myfiles.zip");
                // Retrieve reference to a blob named "myblob".

                CloudBlockBlob blockBlob = container.GetBlockBlobReference(zipFile.Name);
                // Upload the zip and store it in the blob
                using (FileStream fs = zipFile.OpenRead())
                    blockBlob.UploadFromStream(fs);