© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•12mo ago•
13 replies
Mihneas22

✅ AWS S3 with ASP.NET Core

Hello! So I have this code here for a minimal API that returns an image file from a S3 Bucket:

app.MapGet("images/{key}", async (string key, IAmazonS3 s3Client, IOptions<S3Settings> s3Settings) =>
{
    var getRequest = new GetObjectRequest
    {
        BucketName = s3Settings.Value.BucketName,
        Key = $"images/{key}"
    };

    var response = await s3Client.GetObjectAsync(getRequest);

    return Results.File(response.ResponseStream, response.Headers.ContentType, response.Metadata["file-name"]);
});
app.MapGet("images/{key}", async (string key, IAmazonS3 s3Client, IOptions<S3Settings> s3Settings) =>
{
    var getRequest = new GetObjectRequest
    {
        BucketName = s3Settings.Value.BucketName,
        Key = $"images/{key}"
    };

    var response = await s3Client.GetObjectAsync(getRequest);

    return Results.File(response.ResponseStream, response.Headers.ContentType, response.Metadata["file-name"]);
});


What I want is to make this minimal api request into a normal one, like this here:

public async Task<ImageResponse> GetImageAsync(string fileName)
{
    var getRequest = new GetObjectRequest
    {
        BucketName = settings.Value.BucketName,
        Key = $"images/{fileName}"
    };

    var response = await amazonS3.GetObjectAsync(getRequest);

    return new ImageResponse(response.ResponseStream, response.Headers.ContentType, response.Metadata["file-name"]);
}
public async Task<ImageResponse> GetImageAsync(string fileName)
{
    var getRequest = new GetObjectRequest
    {
        BucketName = settings.Value.BucketName,
        Key = $"images/{fileName}"
    };

    var response = await amazonS3.GetObjectAsync(getRequest);

    return new ImageResponse(response.ResponseStream, response.Headers.ContentType, response.Metadata["file-name"]);
}


My error is that I cant return the same type (in the first it is Results.File) and in the second I can't use the same and I am being forced to make a custom one. The thing is, with the second option, I get an error with "HashStream does not support seeking". How am I supposed tot deal with this?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

svelte with asp.net core
C#CC# / help
2y ago
❔ ASP.NET to .net Core
C#CC# / help
3y ago
✅ ASP.NET CORE with React.js or ASP.NET CORE WEB APP
C#CC# / help
3y ago