Skip to content

AmazonS3 PutObjectAsync is uploading object, but throws "AmazonS3Exception" after hanging for some time #3653

Closed
@MartinDybdahlM

Description

@MartinDybdahlM

Describe the bug

We've recently updated the AWSSDK.S3 NuGet package from version 3.7.310.1 to version 3.7.413, but this causes the PutObjectAsync method to hang for some time and then throw an AmazonS3Exception with message Error making request with Error Code InternalServerError and Http Status Code InternalServerError. No further error information was returned by the service.

We can see the object are uploaded to the S3 bucket.

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

The files are uploaded and the method is returning a Task<PutObjectResponse>

Current Behavior

The files are uploaded and the method is hanging for a long time, and then throws an AmazonS3Exception with message Error making request with Error Code InternalServerError and Http Status Code InternalServerError. No further error information was returned by the service.

Reproduction Steps

using Amazon.S3;
using Amazon.S3.Model;
using Microsoft.AspNetCore.Mvc;

namespace Backend.Controllers.ImageController;

[Route("api/[controller]")]
public class ImageController : ControllerBase
{
    private readonly IAmazonS3 _s3Client;

    public ImageController(IAmazonS3 s3Client)
    {
        _s3Client = s3Client;
    }

    public class UploadImageDto
    {
        public required IFormFile Image { get; set; }
    }

    [HttpPost("upload-image")]
    public async Task<ActionResult> UploadImage([FromForm] UploadImageDto dto)
    {
        using var memoryStream = new MemoryStream();
        await dto.Image.CopyToAsync(memoryStream);

        var request = new PutObjectRequest
        {
            BucketName = "my-bucket",
            Key = "my-folder/my-image.jpeg",
            ContentType = "image/jpeg",
            InputStream = memoryStream,
        };

        await _s3Client.PutObjectAsync(request);

        return Ok();
    }
}

Possible Solution

No response

Additional Information/Context

Our workaround for now is to use AWSSDK.S3 3.7.310.1

AWS .NET SDK and/or Package version used

AWSSDK.S3 3.7.413

Targeted .NET Platform

.NET 8

Operating System and version

OSX Sequoia 15.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.p2This is a standard priority issueresponse-requestedWaiting on additional info and feedback. Will move to "closing-soon" in 7 days.s3

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions