gpt4 book ai didi

c# - 使用 C# 代码从 Data Lake Store 读取文件内容

转载 作者:行者123 更新时间:2023-12-03 04:51:06 24 4
gpt4 key购买 nike

我正在尝试从 Azure Data Lake Store 文件读取内容。但是在连接/打开连接时,连接本身失败并抛出异常

 var stream = _adlsFileSystemClient.FileSystem.Open(_adlsAccountName, "/folder1/"+file.PathSuffix);

获取异常为:

Exception of type 'Microsoft.Rest.Azure.CloudException' was thrown.

无法识别该问题。如何解决这个问题?

谢谢

最佳答案

Exception of type 'Microsoft.Rest.Azure.CloudException' was thrown.

这是基本的异常信息。所以请尝试使用fiddler工具来捕获详细的错误信息。

根据您的代码,似乎是找不到文件或授权异常。

1.如果是404错误:请尝试使用以下格式并从azure门户检查文件。

 var srcPath = "/mytempdir/tomtest.txt";
var stream = adlsFileSystemClient.FileSystem.Open(adlsAccountName, srcPath);

enter image description here

2.如果是授权异常,并且您正在使用带有客户端 key 的服务到服务身份验证。请为 azure AD 应用程序分配操作该文件的权限。更多详情请引用document .

enter image description here

enter image description here

以下是我的测试代码和截图:

 var applicationId = "your application Id";
var secretKey = "secret Key";
var tenantId = "Your tenantId";
var adlsAccountName = "adls account name";
var creds = ApplicationTokenProvider.LoginSilentAsync(tenantId, applicationId, secretKey).Result;
var adlsFileSystemClient = new DataLakeStoreFileSystemManagementClient(creds);
var srcPath = "/mytempdir/tomtest.txt";
var destPath = @"F:\tom\testfile.txt";
using (var stream = adlsFileSystemClient.FileSystem.Open(adlsAccountName, srcPath))
using (var fileStream = new FileStream(destPath, FileMode.Create))
{
stream.CopyTo(fileStream);
}

enter image description here

包.config

<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Hyak.Common" version="1.0.2" targetFramework="net452" />
<package id="Microsoft.Azure.Common" version="2.1.0" targetFramework="net452" />
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net452" />
<package id="Microsoft.Azure.Management.DataLake.Store" version="1.0.4" targetFramework="net452" />
<package id="Microsoft.Azure.Management.DataLake.StoreFileSystem" version="0.9.6-preview" targetFramework="net452" />
<package id="Microsoft.Azure.Management.DataLake.StoreUploader" version="1.0.1-preview" targetFramework="net452" />
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net452" />
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net452" />
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net452" />
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="2.28.3" targetFramework="net452" />
<package id="Microsoft.Net.Http" version="2.2.22" targetFramework="net452" />
<package id="Microsoft.Rest.ClientRuntime" version="2.3.5" targetFramework="net452" />
<package id="Microsoft.Rest.ClientRuntime.Azure" version="3.3.5" targetFramework="net452" />
<package id="Microsoft.Rest.ClientRuntime.Azure.Authentication" version="2.2.12" targetFramework="net452" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net452" />
</packages>

关于c# - 使用 C# 代码从 Data Lake Store 读取文件内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42926878/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com