I would like to be able to download files via links in my web app. I am using Amazon S3 to store files in the cloud and am able to retrieve them into a ResponseStream using the example here:
https://docs.aws.amazon.com/AmazonS3/latest/dev/RetrievingObjectUsingNetSDK.html
How do I go from having a ResponseStream to actually being able to download the file in the browser? I do not want to download it to the server, and I want to to be downloaded to the user's downloads folder. I feel like I do not know enough about how to do this to know where to start.
string responseBody = "";
try
{
GetObjectRequest request = new GetObjectRequest
{
BucketName = bucketName,
Key = keyName
};
using (GetObjectResponse response = await client.GetObjectAsync(request))
using (Stream responseStream = response.ResponseStream)
using (StreamReader reader = new StreamReader(responseStream))
{
string contentType = response.Headers["Content-Type"];
responseBody = reader.ReadToEnd(); // Now you process the response body.
// I read the response to the end, how do I create a file and download it?
}
}