我是azure的新手。我在天蓝色门户网站中创建了一个存储帐户。我需要使用ARM模板将文件上传到存储帐户。任何人都可以告诉我怎么做?
答案 0 :(得分:1)
正如Bruno Faria所说,我们无法使用ARM模板来做到这一点。使用Azure ARM模板。您可以在单个协调操作中部署,更新或删除解决方案的所有资源。有关ARM模板的更多详细信息,请参阅document
使用Resource Manager,您可以创建一个模板(采用JSON格式),用于定义Azure解决方案的基础结构和配置。通过使用模板,您可以在整个生命周期内重复部署您的解决方案,并确保您的资源以一致的状态部署
我们可以使用Microsoft Azure Storage Explorer轻松完成这项工作。
如果我们尝试使用程序来执行此操作,我们可以从Azure官方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);
}
答案 1 :(得分:0)
您可以使用AzCopy:
<bean id = "advertisementRepo" class = "com.amstech.mayal.demo.test.AdvertisementRepo" />
更多信息:https://docs.microsoft.com/en-us/azure/storage/storage-use-azcopy
您还可以使用powershell将文件上传到存储帐户:
AzCopy /Source:C:\myfolder /Dest:https://myaccount.blob.core.windows.net/mycontainer /DestKey:key /S
更多信息:https://docs.microsoft.com/en-us/azure/storage/storage-powershell-guide-full
答案 2 :(得分:0)
部署Blob Storage容器是ARM模板中的一项新功能。
这是我发现的博客,该博客解释了如何做:deploying-blob-containers-with-arm-templates。
以下是博客中的模板示例,该示例确实做到了:(记入@johndownshere)
{
"$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageAccountName": {
"type": "string"
}
},
"variables": {
"containerName": "logs"
},
"resources": [
{
"name": "[parameters('storageAccountName')]",
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2018-02-01",
"location": "[resourceGroup().location]",
"kind": "StorageV2",
"sku": {
"name": "Standard_LRS",
"tier": "Standard"
},
"properties": {
"accessTier": "Hot"
},
"resources": [
{
"name": "[concat('default/', variables('containerName'))]",
"type": "blobServices/containers",
"apiVersion": "2018-03-01-preview",
"dependsOn": [
"[parameters('storageAccountName')]"
]
}
]
}
]
}