Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 231
Ismayil S Avatar asked Oct 17 '25 01:10

Ismayil S


1 Answers

Just quickly looking at the docs, you maybe able to do this

using (GetObjectResponse response = client.GetObject(request))
   bytes = response.ResponseStream.ToArray();
like image 129
TheGeneral Avatar answered Oct 18 '25 15:10

TheGeneral