繁体   English   中英

从 azure 函数连接到 Azure 数据湖 Gen 2

[英]Connection to Azure data lake Gen 2 from azure function

我正在尝试从 Azure 函数连接到 Azure Data Lake Storage Gen2 以导入一些 XML 文件并将它们转换为 JSON。 但我的代码不起作用:

var creds = ApplicationTokenProvider.LoginSilentAsync(tenantId, applicationId, secretKey).Result;  
var adlsFileSystemClient = new DataLakeStoreFileSystemManagementClient(creds);
var result = adlsFileSystemClient.FileSystem.Open(adlsAccountName, "/Test/xml.xml");

这将返回一个错误: The remote name could not be resolved +“azuredatalakestore.net”,而实际上 DNS 后缀应该不同。

截至目前,ADLS Gen2 不支持 SDK,但您可以使用ADLS Gen2 rest api代替,执行一些创建/读取/删除操作。

例如,您可以使用 sas 令牌身份验证编写如下代码(或者您也可以使用共享密钥身份验证):

            string sasToken = "?sv=2018-03-28&ss=b&srt=sco&sp=rwdl&st=2019-04-15T08%3A07%3A49Z&se=2019-04-16T08%3A07%3A49Z&sig=xxxx";
            string url = "https://xxxx.dfs.core.windows.net/myfilesys1/app.JPG" + sasToken;
            var req = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));

            //you can specify the Method as per your operation as per the api doc
            req.Method = "HEAD"; 
            var res = (HttpWebResponse)req.GetResponse();

            //your other code

取自Azure Data Lake Storage Gen2 的已知问题

对 Data Lake Storage Gen2 帐户的 SDK 支持
没有可用于 Data Lake Storage Gen2 帐户的 SDK。

SDK 现在可用: https : //docs.microsoft.com/en-us/azure/storage/blobs/data-lake-storage-directory-file-acl-dotnet

我的例子:

StorageSharedKeyCredential credential = new StorageSharedKeyCredential(_configuration["AccountName"], _configuration["AccountKey"]);

serviceClient = new DataLakeServiceClient(new Uri(_configuration["DFSURL"]), credential);

usage_container = serviceClient.GetFileSystemClient(_configuration["BlobContainer"]);


DataLakeDirectoryClient directoryClient = usage_container.GetDirectoryClient(country);
directoryClient.CreateFileAsync(xmlFileName, headers);

暂无
暂无

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

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