I am trying to get an object from AWS S3 bucket using AWS SDK.
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();
AWSFile file = new AWSFile();
file.ContentType = contentType;
file.FileContent = responseBody
return file;
}
How can I process the response body to return a file from the controller?
Controller
public async Task<object> DownloadAttachment(string filename)
{
try
{
var request = await _requestService.DownloadAttachmentAsync(filename);
return File(request.FileContent,request.ContentType, "Vue Cheat Sheet.pdf");
}
catch (Exception ex)
{
return StatusCode(500, ex.Message);
}
}
Tried many things but could not succeed
AWSSDK.S3 nuget package is required.
filename:- {any directory}/{name}.{txt | json | *}
downloadfile:- {name}.{txt | json |*}
{} are used as placeholder, put your required filename and extension.