1

I want to load an audio file via the PutObjectAsync() method but after a while this exception is thrown:

ex = {"Your socket connection to the server was not read from or written to within the timeout period."}

For a .txt file this method works very well but once I load a file other than .txt the exception is thrown.

  • size of my txt file: 2MB (works)
  • size of my mp3 file: 700Ko (does not work)

My code:

using(var inputStream = new MemoryStream())
{
  await request.File.CopyToAsync(inputStream);
  var putObjectRequest = new PutObjectRequest(){
    BucketName = "<my_bucket_name>",
    Key = "<file_key>",
    InputStream = inputStream,
  };
  await s3Client.PutObjectAsync(putObjectRequest);
}

I am using:

  • .NET 6
  • AWSSDK.S3: Version="3.7.9.42"

can someone help me please?

Bemn
  • 1,291
  • 1
  • 7
  • 22
elmedhi57
  • 11
  • 1
  • Did you ever manage to solve this OP? I am having the exact same issue and it is driving me nuts ! – wazdev Apr 01 '23 at 04:22

1 Answers1

0

I came across this issue while trying to connect to OVHCloud via the AWSSDK S3 API. After a lot of trial and error, I found that chunking doesn't work, and you also need to explicitly set the http status (UseHttp - note that false means https).

I hope this saves someone else the countless hours it cost me.

_s3Client = new AmazonS3Client(AccessKey, SecretKey, new AmazonS3Config
{
    ServiceURL = ServiceURL,
    AuthenticationRegion = Region,
    UseHttp = false
});



var putObjectRequest = new PutObjectRequest
{
    UseChunkEncoding = false,
    BucketName = BucketName,
    Key = key,
    InputStream = fileStream
};

await _s3Client.PutObjectAsync(putObjectRequest);
wazdev
  • 323
  • 4
  • 11