繁体   English   中英

从 Azure Storage FileShare 读取文件数据

[英]Read file data from Azure Storage FileShare

我正在尝试从我的 Azure 存储的 FileShare 中存在的文件(json 文件)中读取数据。 我不想下载文件,而只是读取并获取数据。 以下命令为我下载文件,而不是读取数据并将其存储在变量中。 请帮忙。

$fileContents = Get-AzStorageFileContent -ShareName $fileShareName -Path $filePath -Context (Get-AzStorageAccount -ResourceGroupName $ResourceGroupName -Name "name").Context -OutVariable fileContents

我如何读取数据并可能在 filshare 中发布文件? 我一直在关注此文档,但找不到解决方案。

我在我的环境中尝试并得到以下结果:

最初我尝试使用以下命令从 azure-file share 读取文件并下载它。

命令:

$accountName = "venkat123"
$accountKey = "<storage account key >"
$fileshareName = "fileshare1"
$Name = "directory1/file.json"
$content="<downloaded path\file.json>"

$ctx = New-AzStorageContext -StorageAccountName $accountName -StorageAccountKey $accountKey

Get-AzStorageFileContent -ShareName $fileShareName -Path $Name -Destination "file.json" -Context $ctx
Get-content -path $content

安慰:

在此处输入图像描述

作为解决方法,如果您需要在不下载的情况下读取 azure 文件共享中的文件,您可以使用下面的 python 代码。

代码:

from  azure.storage.file  import  FileService

storageAccount='venkat123'
accountKey='xxxxxxx'
file_service = FileService(account_name=storageAccount, account_key=accountKey)

share_name="fileshare1"

directory_name="directory1"

file_name="file.json"

file = file_service.get_file_to_text(share_name, directory_name, file_name)

print(file.content)

安慰:在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM