【发布时间】:2017-07-12 09:26:45
【问题描述】:
我想将本地文件附加到数据湖上的文件中。有人可以给我举个例子,什么是使用 .net sdk 连接数据湖存储的最佳方式。
【问题讨论】:
标签: .net azure azure-data-lake
我想将本地文件附加到数据湖上的文件中。有人可以给我举个例子,什么是使用 .net sdk 连接数据湖存储的最佳方式。
【问题讨论】:
标签: .net azure azure-data-lake
如果您想在没有登录表单的情况下静默登录,这是解决方案:
string _username = <your azure username>
string _pass = <your azure password>
string _adlsAccountName = <name of your data lake store>
string _subId = <your subscription id>
string localFolderPath = @"<yourfolderpath>"
string localFilePath = Path.Combine(localFolderPath, "<yourFile>");
string remoteFolderPath = "/path on data lake/";
string remoteFilePath = Path.Combine(remoteFolderPath, "yourFileonDataLake");
var tenantId = "<your tenant id>"; //you can find this in right top corner on azure portal
var nativeClientApp_clientId = "1950a258-227b-4e31-a9cf-717495945fc2"; // you can use this one
var activeDirectoryClientSettings = ActiveDirectoryClientSettings.UsePromptOnly(nativeClientApp_clientId, new Uri("urn:ietf:wg:oauth:2.0:oob"));
var creds = UserTokenProvider.LoginSilentAsync(nativeClientApp_clientId, tenantId, _username, _password).Result;
_adlsClient = new DataLakeStoreAccountManagementClient(creds) { SubscriptionId = _subId };
_adlsFileSystemClient = new DataLakeStoreFileSystemManagementClient(creds);
如果您想在数据湖上使用表单登录,只需使用 UserTokenProvider 中的 LoginWithPromptAsyncMethod。
这是设置。现在您可以通过 _adlsFileSystemClient 使用 Upload、Append 等。希望这会对某人有所帮助。
【讨论】:
此 GitHub 存储库中说明了身份验证:https://azure.microsoft.com/en-us/resources/samples/data-lake-analytics-dotnet-auth-options/
有几个基本步骤: - 收集您需要进行身份验证的信息 - 客户端 ID、令牌受众、租户 ID 等。 - 使用该信息获得证书。该存储库中的函数 GetCreds_User_Popup 包含交互式最终用户身份验证所需的代码 - 最后,使用凭据,创建您需要的 .NET 客户端对象
【讨论】: