title: AWS S3 File Upload .NET SDK (.NET Core) Unable to write data to the transport connection
body: <p>I'm writing a function to upload multiple files to AWS S3. Even with a single file, the commented code using TransferUtilityUploadRequest below fails with an error:</p>
  <blockquote>
  <p>System.IO.IOException: Unable to write data to the transport
  connection: An existing connection was forcibly closed by the remote
  host.</p>
  </blockquote>
  <p>The uncommented code works, (but I am unable to set ACL permissions). Having looked at several examples online, I am not sure what I am doing wrong? The RequestFormLimits are not this issue here, the code fails at the point it tries to upload to S3.</p>
  <pre><code>    [HttpPost(&quot;test/raw-file-upload-s3&quot;)]
  [RequestFormLimits(MultipartBodyLengthLimit = 1073741824)]
      [RequestSizeLimit(1073741824)]
      public async Task&lt;ActionResult&lt;object&gt;&gt; UploadFiles3(IList&lt;IFormFile&gt; files)
      {
          var regionEndpoint = RegionEndpoint.GetBySystemName(_awsS3RegionEndpoint);
  
          var uploadedFileNames = new List&lt;string&gt;();
  
          using (var awsS3Client = new AmazonS3Client(new BasicAWSCredentials(_awsAccessKeyId, _awsSecretKey), regionEndpoint))
          {
              using (var fileTransferUtility = new TransferUtility(awsS3Client))
              {
                  var dateBasedDirectoryName = GetDateBasedDirectoryName();
  
                  string contentDirectory = $@&quot;example/&quot;;
  
                  var tasks = new Task[files.Count];
  
                  var streams = new Stream[files.Count];
  
                  for (int i = 0; i &lt; files.Count; i++)
                  {
                      string fileName = $&quot;{Guid.NewGuid()}_{files[i].FileName}&quot;;
  
                      string key = $&quot;{contentDirectory}{fileName}&quot;;
  
                      streams[i] = files[i].OpenReadStream();
  
                      tasks[i] = fileTransferUtility.UploadAsync(streams[i], _awsS3AssetsBucket, key);
  
                      // var fileTransferUtilityRequest = new TransferUtilityUploadRequest
                      // {
                      //     BucketName = _awsS3AssetsBucket,
                      //     Key = key,
                      //     CannedACL = S3CannedACL.PublicRead,
                      //     InputStream = streams[i]
                      // };
  
                      // tasks[i] = fileTransferUtility.UploadAsync(fileTransferUtilityRequest);
                  }
  
                  await Task.WhenAll(tasks).ConfigureAwait(false);
  
                  for (int i = 0; i &lt; files.Count; i++)
                  {
                      streams[i].Close();
                  }
              }
          }
  
          return new
          {
              uploadedFiles = uploadedFileNames
          };
      }
  </code></pre>