【问题标题】:How to add/upload the static files into specific path of the Azure Blob Storage Container如何将静态文件添加/上传到 Azure Blob 存储容器的特定路径
【发布时间】:2021-10-30 08:09:51
【问题描述】:

我开发了以下 PowerShell 脚本,用于在 Azure Blob 存储容器中创建文件夹。

Param(
  [Parameter(Mandatory = $True)]
  [string]
  $resourceGroupName,

  [Parameter(Mandatory = $True)]
  [string]
  $storageAccountName
)

$storageAccount = Get-AzStorageAccount -ResourceGroupName $resourceGroupName -AccountName $storageAccountName
$ctx = $storageAccount.Context
$dirs = @('ABC', 'XYZ', 'ABC123', 'XYZ123')
$subdirs = @('Archive', 'Logs')
Foreach ($d in $dirs) {
  ForEach ($s in $subdirs) {
    New-AzDataLakeGen2Item -Context $ctx -FileSystem $filesystemName -Path $d/$s -Directory
  }
}

我想将.xml 文件添加/上传到 Azure Blob 存储容器的特定文件夹路径 (ABC123/Logs)。

【问题讨论】:

  • 请编辑您的问题并提供有关您在脚本中遇到的问题的详细信息。

标签: azure powershell azure-blob-storage


【解决方案1】:

我已使用以下脚本通过 `New-AzDataLakeGen2Item cmdlet 将文件上传到目录。

参考文档:Upload a file to a directory

Param(
  [Parameter(Mandatory = $True)]
  [string]
  $resourceGroupName,

  [Parameter(Mandatory = $True)]
  [string]
  $storageAccountName,
   
  [Parameter(Mandatory = $True)]
  [string]
  $filesystemName,

  [Parameter(Mandatory = $True)]
  [string]
  $localSrcFilesPath
)

Write-Host "Starting to create the directory references...."

$storageAccount = Get-AzStorageAccount -ResourceGroupName $resourceGroupName -AccountName $storageAccountName

$ctx = $storageAccount.Context

$dirs = @('ABC', 'XYZ')
$subdirs = @('Archive', 'Logs')

Foreach ($d in $dirs) {

  ForEach ($s in $subdirs) {

    New-AzDataLakeGen2Item -Context $ctx -FileSystem $filesystemName -Path $d/$s -Directory

    $files= Get-ChildItem $localSrcFilesPath

    foreach($file in $files){

        $localSrcFile =  "$localSrcFilesPath\$file"
        $destPath = "$d/$s/$file"

        if("$d/$s" -eq 'ABC/Logs'){

            Write-Host "Starting to upload file: "$destPath

            New-AzDataLakeGen2Item -Context $ctx -FileSystem $filesystemName -Path $destPath -Source $localSrcFile -Force
            
            Write-Host "Completed to upload file:" $destPath "into Azure Storage Blob Container"

        }
    }

  }
}

Write-Host "Completed to create the directory references"

【讨论】:

    猜你喜欢
    • 2022-01-12
    • 2019-08-13
    • 2020-01-28
    • 2018-01-10
    • 1970-01-01
    • 2017-01-24
    • 2017-08-19
    • 2019-07-10
    相关资源
    最近更新 更多