title: AWSSDK S3 for ASP.NET Core
body: <p>I have tried to upload file to Amazon S3 using AWSSDK for .NET Core, but I always got exception like below:</p>
  
  <blockquote>
    <p>The write operation failed, see inner exception.</p>
    
    <p>The connection with the server was terminated abnormally</p>
  </blockquote>
  
  <p>No matter connect to Singapore (Global) or Beijing (cn-north-1), it still has problem. </p>
  
  <p>Can anyone give me some suggestions to solve this problem?</p>
  
  <p>This is version and codes, please!</p>
  
  <blockquote>
    <p>.NET Core / 1.1.1<br>
    AWSSDK.S3 / 3.3.5.10</p>
  </blockquote>
  
  <p><strong>Startup.cs</strong></p>
  
  <pre><code>// Add framework services.
  services.AddMvc();
  services.AddDefaultAWSOptions(Configuration.GetAWSOptions());
  services.AddAWSService&lt;IAmazonS3&gt;();
  </code></pre>
  
  <p><strong>appsettings.json</strong></p>
  
  <pre><code>"AWS_ACCESS_KEY_ID": "xxxxxxxxxx",
  "AWS_SECRET_ACCESS_KEY": "xxxxxxxxxxxxxxxxxxxxxxxx",
  "AWS": {
    "Region": "cn-north-1",
    "ServiceURL": "https://s3.cn-north-1.amazonaws.com.cn"
  }
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>private readonly IAmazonS3 _AmazonS3Client;
  
  public UsersController(
         IAmazonS3 AmazonS3Client)
  {
       _AmazonS3Client = AmazonS3Client;
  }
  
  
  [HttpPost]
  [Route("users/picture/upload")]
  public async Task&lt;IActionResult&gt; UploadUserPhoto(string UserId)
  {
      Amazon.S3.Model.PutObjectResponse response = await 
         _AmazonS3Client.PutObjectAsync(
         new Amazon.S3.Model.PutObjectRequest()
         {
             BucketName = "mybucket",
             Key = fileName,
             InputStream = uploadFiles[0].OpenReadStream(),
             CannedACL = S3CannedACL.PublicRead
         });
  }
  </code></pre>