gpt4 book ai didi

c# - 当我从 AWS 迁移到 Azure Data Lake 时,如何避免存储此文件?

转载 作者:行者123 更新时间:2023-12-03 01:43:19 25 4
gpt4 key购买 nike

我正在编写一个 Azure 函数,将文件从 AWS S3 移动到 Azure Datalake,我可以进行下载,也可以进行上传,但我很难将两者拼凑在一起,因为我不想将文件存储在中间应用程序可以说是因为 azure 函数本身不需要存储它,只需将其传递即可。

解释起来并不容易,所以请耐心等待我尝试解释我想做什么。

当我使用此代码从 S3 下载时

await client.GetObjectAsync(new GetObjectRequest { BucketName = bucketName, Key = entry.Key });

我没有文件系统来存储它,我不想存储它,我希望它作为某种“对象”,我可以直接传递给azure数据湖编写器,如下所示

adlsFileSystemClient.FileSystem.UploadFile(adlsAccountName, source, destination, 1, false, true);

如果我将其下载到本地磁盘,然后上传,代码可以正常工作,但这不是我想要的,因为 azure 函数没有存储空间,我想将下载的对象直接传递给上传者,可以这么说

我怎样才能实现这个目标?

**** 编辑 ****

// Process the response.
foreach (S3Object entry in response.S3Objects)
{
Console.WriteLine("key = {0} size = {1}", entry.Key.Split('/').Last(), entry.Size);
string fileNameOnly = entry.Key.Split('/').Last();

//await client.GetObjectAsync(new GetObjectRequest { BucketName = bucketName, Key = entry.Key });
GetObjectResponse getObjRespone = await client.GetObjectAsync(bucketName, entry.Key);
MemoryStream stream = new MemoryStream();
getObjRespone.ResponseStream.CopyTo(stream);

if (entry.Key.Contains("MerchandiseHierarchy") == true)
{
WriteToAzureDataLake(stream, @"/PIMRAW/MerchandiseHierarchy/" + fileNameOnly);
}
}

然后我将内存流传递给azure方法,但我需要一个streamuploader,但我无法找到它,以下提示它无法将流转换为字符串

adlsFileSystemClient.FileSystem.UploadFile(adlsAccountName, source, destination, 1, false, true);

*编辑2*

按如下方式更改上传方法,它会在目标位置创建文件,但大小为 0,所以我想知道我是否在下载完成之前创建文件?

static void WriteToAzureDataLake(MemoryStream inputSource, string inputDestination)
{

// 1. Set Synchronization Context
SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());

// 2. Create credentials to authenticate requests as an Active Directory application
var clientCredential = new ClientCredential(clientId, clientSecret);

var creds = ApplicationTokenProvider.LoginSilentAsync(tenantId, clientCredential).Result;

// 2. Initialise Data Lake Store File System Client
adlsFileSystemClient = new DataLakeStoreFileSystemManagementClient(creds);

// 3. Upload a file to the Data Lake Store
//var source = @"c:\nwsys\source.txt";
var source = inputSource;

//var destination = "/PIMRAW/MerchandiseHierarchy/destination.txt";
var destination = inputDestination;

//adlsFileSystemClient.FileSystem.UploadFile(adlsAccountName, source, destination, 1, false, true);
adlsFileSystemClient.FileSystem.Create(adlsAccountName, destination, source);


// FINISHED
Console.WriteLine("6. Finished!");

}

最佳答案

Change the upload method as follows and it creates the file at destination but with 0 size

似乎需要在写入datalake之前将流位置设置为0。

stream.Position = 0;

关于c# - 当我从 AWS 迁移到 Azure Data Lake 时,如何避免存储此文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50460237/

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