简体   繁体   English

如何从 AWS S3 存储下载文件作为字节数组?

[英]How to download a file as Byte Array from AWS S3 Storage?

I can download a file from the Amazon S3 Storage with below code,我可以使用以下代码从 Amazon S3 存储下载文件,

var s3Client = new AmazonS3Client(txt_Accesskey.Text, txt_Secretkey.Text, bucketRegion);
GetObjectRequest request = new GetObjectRequest();
request.BucketName = bucketName;
request.Key = "Sample.txt";
GetObjectResponse response = s3Client.GetObject(request);
response.WriteResponseStreamToFile(@"C:\Desktop\Sample.txt");

But, I want to download these files as Byte Array.但是,我想将这些文件下载为字节数组。 Can anyone please give me a solution for this?任何人都可以请给我一个解决方案吗?

Just quickly looking at the docs , you maybe able to do this只需快速查看文档,您也许可以做到这一点

using (GetObjectResponse response = client.GetObject(request))
   bytes = response.ResponseStream.ToArray();

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

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