问题描述
我想做一些简单的事情!!!
通过 Azure 函数中的 c# 代码将 blob 从位于 dataLake gen 2 (SourceContainer
) 中的容器 (SourceDataLake
) 复制到第二个 DatLake (TargetDataLake
)。
我的 Azure Function 和 SourceDataLake
之间的连接通过专用链接和专用端点进行保护。
DataLakeDirectoryClient sourcedirectoryClient2 = sourceDataLakeFileSystemClient.GetDirectoryClient(myPath);
DataLakeFileClient sourcefileClient = sourcedirectoryClient2.GetFileClient(myBlobName);
Response<FileDownloadInfo> downloadResponse = await sourcefileClient.ReadAsync(); //I get the error in this line
Stream reader = downloadResponse.Value.Content;
DataLakeDirectoryClient targetdirectoryClient = taregetDataLakeFileSystemClient.GetDirectoryClient(TargetDirectory);
DataLakeFileClient targetfileClient = await targetdirectoryClient.CreateFileAsync(myBlobName);
await targetfileClient.UploadAsync(reader,true);
对于 DataLake 的身份验证,我使用此功能:
public static DataLakeFileSystemClient GetDataLakeFileSystemClient(string containerName,string dataLakeName,string dataLakeAccessKey)
{
StorageSharedKeyCredential storageSharedKeyCredential = new StorageSharedKeyCredential(dataLakeName,dataLakeAccessKey);
DataLakeClientOptions options = new DataLakeClientOptions(DataLakeClientOptions.ServiceVersion.V2019_07_07);
DataLakeServiceClient dataLakeServiceClient = new DataLakeServiceClient(
new Uri(string.Concat("https://",dataLakeName,".dfs.core.windows.net")),storageSharedKeyCredential,options);
DataLakeFileSystemClient dataLakeFileSystemClient = dataLakeServiceClient.GetFileSystemClient(containerName);
return dataLakeFileSystemClient;
}
此代码对我不起作用。如果我从 SourceDataLake
中删除 Priavet Link Private Endpoint,则它可以工作。不知何故私有链接和私有端点不适用于这行代码:
Response<FileDownloadInfo> downloadResponse = await sourcefileClient.ReadAsync();
你知道我该如何解决这个问题吗?或者有什么更好的方法可以从 DataLake gen2 复制 blob?
解决方法
抱歉,我无法解决当前的问题,但是当您询问其他选项时,我认为您可以探索 Azure 数据工厂。 https://docs.microsoft.com/en-us/azure/data-factory/connector-azure-data-lake-storage