简体   繁体   中英

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,

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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