Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

upload file to storage account using ARM template

I am new to azure. I have a storage account created in the azure portal. I need to upload files to the storage account using ARM templates. Can any one please let me know how to do this?

like image 997
Balarka Davuluri Avatar asked Jul 31 '17 22:07

Balarka Davuluri


1 Answers

As Bruno Faria mentioned that we could not use ARM template to do that. With Azure ARM template. You can deploy, update, or delete all the resources for your solution in a single,coordinated operation. More detail about ARM template please refer to the document

With Resource Manager, you can create a template (in JSON format) that defines the infrastructure and configuration of your Azure solution. By using a template, you can repeatedly deploy your solution throughout its lifecycle and have confidence your resources are deployed in a consistent state

We could use Microsoft Azure Storage Explorer to do that easily.

enter image description here

If we try to use program to do that we could get the demo code from Azure official document.

// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
    CloudConfigurationManager.GetSetting("StorageConnectionString"));

// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

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

// Retrieve reference to a blob named "myblob".
CloudBlockBlob blockBlob = container.GetBlockBlobReference("myblob");

// Create or overwrite the "myblob" blob with contents from a local file.
using (var fileStream = System.IO.File.OpenRead(@"path\myfile"))
{
    blockBlob.UploadFromStream(fileStream);
}
like image 185
Tom Sun - MSFT Avatar answered Sep 30 '22 16:09

Tom Sun - MSFT