The connection with the server was terminated abnormally (AWS S3 file upload)

1.1k Views Asked by At

Using the following code to upload a gzip file to S3:

class Program
{
    public static AWSCredentials credentials;

    static Program()
    {
        var chain = new CredentialProfileStoreChain();
        if (!chain.TryGetAWSCredentials("awsConfig", out credentials))
            throw new Exception("AWS Credentials not found!!");
    }

    static void Main(string[] args)
    {
        var filePath = $@"C:\temp\test.gz";
        UploadFile("myBucket", filePath, "test");
    }

    private static void UploadFile(string bucketName, string filePath, string prefixKey)
    {
        TransferUtility fileTransferUtility = new TransferUtility(new AmazonS3Client(credentials, Amazon.RegionEndpoint.USEast1));

        TransferUtilityUploadRequest fileTransferUtilityRequest = new TransferUtilityUploadRequest
        {
            BucketName = bucketName,
            FilePath = filePath,
            Key = prefixKey,
        };

        fileTransferUtility.Upload(fileTransferUtilityRequest);
        Console.WriteLine("Upload completed");
    }
}

I am getting the error The write operation failed, see inner exception where the inner exception is System.Net.Http.WinHttpException: The connection with the server was terminated abnormally

I thought it could be a network problem so I uploaded the application to an EC2 instance in the same region as the bucket and still getting the same error.

The file test.gz is a file with gzip compression and its size is 274kb.

This problem happens only with some files all compressed the same way.

What could be the reason of this error?

Let me know if you need the file to test.

Here is the complete stack trace: https://pastebin.com/RJ8QSmSK

0

There are 0 best solutions below