簡體   English   中英

通過 Azure 函數中的 C# 將文件從一個 DataLake Gen2 復制到另一個 Data Lake Gen 2

[英]Copy file from one DataLake Gen2 to another Data Lake Gen 2 via C# in Azure Functions

我想做簡單的事!!!

通過 Azure 函數中的 c# 代碼將位於 dataLake gen 2 ( SourceDataLake ) 中的容器 ( SourceContainer ) 中的 blob 復制到第二個 DatLake ( TargetDataLake )。

我的 Azure Function 和SourceDataLake之間的連接是通過 Private Link 和 Private Endpoint 保護的。

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 的身份驗證,我使用這個 function:

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,那么它可以工作。 不知何故 Private 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM