I have a .net web API that downloads objects from Amazon S3 to the disk using AWS SDK lib.
using Amazon.S3;
using Amazon.S3.Model;
using System.IO;
private void DownloadObject()
{
BasicAWSCredentials awsCredentials = new Amazon.Runtime.BasicAWSCredentials("MyAccessKey", "MySecretKey");
IAmazonS3 client = new Amazon.S3.AmazonS3Client(awsCredentials, Amazon.RegionEndpoint.USEast1);
GetObjectRequest request = new GetObjectRequest
{
BucketName = "mybucket",
Key = "test.pdf"
};
using (GetObjectResponse response = await client.GetObjectAsync(request))
{
using (Stream responseStream = response.ResponseStream)
{
using (StreamReader reader = new StreamReader(responseStream))
{
string responseBody = await reader.ReadToEndAsync();
File.WriteAllText("C:\\test.pdf", responseBody);
}
}
}
}
Now when I download the files, the file size is too big and If I open a pdf all pages are blank and if I open png file I can't open them.
Anyone can help me to resolve this issue?