Ismayil S
Ismayil S

Reputation: 243

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?

Upvotes: 4

Views: 10725

Answers (1)

TheGeneral
TheGeneral

Reputation: 81493

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

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

Upvotes: 3

Related Questions