'How to Convert AWS S3 bucket stream response into a file in .NET Core
I created a utility class for Amazon AWS S3 bucket related stuff so that I can reuse the utility in different controllers.
I am trying to get the file from S3 bucket I am able to fetch the file as a stream, now I want convert it into an original file, but when I am trying to return the File, I am getting an error
Non-invocable member 'File' cannot be used like a method
Is there a way to convert stream into a file through a class not from the controller.
Here is my code:
public async Task GetFileFromBucket(string fileName)
{
var response = await client.GetObjectAsync(_bucket, fileName);
return File(response.ResponseStream, response.Headers["Content-Type"]);
}
Solution 1:[1]
Is there a way to convert stream into a file through a class not from the Controller
The File Contents is either a string or a stream:
public async Task<string> GetFileFromBucket(string fileName)
{
var response = await client.GetObjectAsync(_bucket, fileName);
return new File(response.ResponseStream, response.Headers["Content-Type"]).ReadAllText();
}
If you want the S3 bucket or file meta data then call a different S3 API. I'm assuming you want the file contents.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jeremy Thompson |
