Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using AWS SDK to upload file to S3 in .NET Core

I'm attempting to use this documentation to upload a file to my S3 bucket using the AWS SDK. Unfortunately, there does not seem to be any documentation giving an example of how to do this in .NET Core, only how to create and inject an instance of IAmazonS3.

Here is what I have:

private IAmazonS3 client; //Being injected
private string bucketName;

using (client)
{
    var request = new PutObjectRequest
    {
        BucketName = bucketName,
        Key = "keyTest",
        ContentBody = "sample text"
    };
    var response = await client.PutObjectAsync(request);
}

When it calls the PutObjectAsync() line, it hangs for 30 seconds or so and then throws a "The HTTP redirect request failed" exception.

All the documentation I'm seeing is for PutObject() not PutObjectAsync(). The client instance I have only exposes async methods.

like image 827
im1dermike Avatar asked Jan 27 '26 05:01

im1dermike


1 Answers

Brutal. I had my IAmazonS3 client pointing at us-west-1, but it was a different region (us-west-2).

like image 182
im1dermike Avatar answered Jan 29 '26 18:01

im1dermike



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!