title: Upload to AWS Server Upload Fails?
body: <p>I am trying to upload a photo to AWS S3, I have followed all the steps to do so. The code is triggered once the user select a photo from UIImagePickerController. Then the code uploads that image to the AWS S3 database. However upon completion of upload this error appears </p>
  
  <blockquote>
    <p>Error Domain=com.amazonaws.AWSS3TransferUtilityErrorDomain Code=1
    "(null)" UserInfo={Server=AmazonS3, Transfer-Encoding=Identity,
    Connection=close, Content-Type=application/xml, Date=Wed, 27 Feb 2019
    08:33:44 GMT, x-amz-request-id=B019306141A5FD4E,
    x-amz-id-2=nWHJCqbpTUAbNI65pNAIxzl8qXOn6y2jNg16CbvUCH/4wtqCYhVBqh86ZN6OYIV1pROSlnUA220=,
    x-amz-bucket-region=ap-southeast-1})</p>
  </blockquote>
  
  <p>I am not sure how to fix this, Any help would be appreciated to successfully upload a photo.</p>
  
  <p>Thanks</p>
  
  <p>Code</p>
  
  <pre><code> @objc func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
  
      let imageAWSName = "ios_123.jpg" //+ NSUUID().uuidString + ".jpg"
  
      let image = info[UIImagePickerController.InfoKey.originalImage] as! UIImage
      let documentDirectory = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!
      let photoURL          = NSURL(fileURLWithPath: documentDirectory)
      let localPath         = photoURL.appendingPathComponent(imageAWSName)
  
      if !FileManager.default.fileExists(atPath: localPath!.path) {
          do {
              //try UIImageJPEGRepresentation(image, 1.0)?.write(to: localPath!)
              try image.jpegData(compressionQuality: 1.0)?.write(to: localPath!)
              print("file saved")
          }catch {
              print("error saving file")
          }
      }
      else {
          print("file already exists")
      }
       //    let credentialProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: “your identity pool id”) //    let configuration = AWSServiceConfiguration(region: .APSoutheast1, credentialsProvider: credentialProvider) //    AWSServiceManager.default().defaultServiceConfiguration = configuration
  
      let s3BucketName = "adnexio-directory"
      //let compressedImage = image.resizableImage(withCapInsets: CGSize(width: 80, height: 80))
      let data: Data = image.pngData()!
      let remoteName = "IOSTEST.png"
      print("REMOTE NAME : ",remoteName)
  
      let expression = AWSS3TransferUtilityUploadExpression()
      expression.progressBlock = { (task, progress) in
          DispatchQueue.main.async(execute: {
              // Update a progress bar
              print("progress: ")
              print(progress)
          })
      }
  
      var completionHandler: AWSS3TransferUtilityUploadCompletionHandlerBlock?
      completionHandler = { (task, error) -&gt; Void in
          DispatchQueue.main.async(execute: {
              print("error: ")
              print(error)
              // Do something e.g. Alert a user for transfer completion.
              // On failed uploads, `error` contains the error object.
          })
      }
  
      let transferUtility = AWSS3TransferUtility.default()
      transferUtility.uploadData(data, bucket: s3BucketName, key: remoteName, contentType: "image/png", expression: expression, completionHandler: completionHandler).continueWith{ (task) -&gt; Any? in
  
          if let error = task.error {
              print("Error : \(error.localizedDescription)")
          }
  
          if task.result != nil {
              let url = AWSS3.default().configuration.endpoint.url
              let publicURL = url?.appendingPathComponent(s3BucketName).appendingPathComponent(remoteName)
              if let absoluteString = publicURL?.absoluteString {
                  // Set image with URL
                  print("Image URL : ",absoluteString)
              }
          }
  
          return nil
  
  
      }
  
  
      picker.dismiss(animated: true, completion: nil)
  
      }
  </code></pre>
  
  <p>Full error report</p>
  
  <pre><code>REMOTE NAME :  IOSTEST.png
  Image URL :  https://s3.us-east-2.amazonaws.com/adnexio-directory/IOSTEST.png
  2019-02-27 16:33:33.867505+0800 Adnexio[3854:1137756] [discovery] errors encountered while discovering extensions: Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled}
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.0400 / Completed: 131072 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.0499 / Completed: 163840 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.0599 / Completed: 196608 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.0599 / Completed: 196608 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.0599 / Completed: 196608 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.0599 / Completed: 196608 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.0699 / Completed: 229376 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.0799 / Completed: 262144 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.0899 / Completed: 294912 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.0999 / Completed: 327680 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.1099 / Completed: 360448 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.1199 / Completed: 393216 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.1298 / Completed: 425984 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.1398 / Completed: 458752 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.1498 / Completed: 491520 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.1598 / Completed: 524288 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.1798 / Completed: 589824 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.1798 / Completed: 589824 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.1898 / Completed: 622592 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.1998 / Completed: 655360 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.2097 / Completed: 688128 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.2197 / Completed: 720896 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.2397 / Completed: 786432 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.2397 / Completed: 786432 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.2497 / Completed: 819200 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.2697 / Completed: 884736 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.2697 / Completed: 884736 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.2797 / Completed: 917504 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.2996 / Completed: 983040 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.2996 / Completed: 983040 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.3096 / Completed: 1015808 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.3196 / Completed: 1048576 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.3296 / Completed: 1081344 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.3396 / Completed: 1114112 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.3596 / Completed: 1179648 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.3596 / Completed: 1179648 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.3696 / Completed: 1212416 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.3795 / Completed: 1245184 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.3895 / Completed: 1277952 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.4095 / Completed: 1343488 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.4095 / Completed: 1343488 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.4195 / Completed: 1376256 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.4395 / Completed: 1441792 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.4395 / Completed: 1441792 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.4495 / Completed: 1474560 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.4594 / Completed: 1507328 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.4694 / Completed: 1540096 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.4894 / Completed: 1605632 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.4894 / Completed: 1605632 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.5094 / Completed: 1671168 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.5094 / Completed: 1671168 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.5194 / Completed: 1703936 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.5294 / Completed: 1736704 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.5393 / Completed: 1769472 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.5593 / Completed: 1835008 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.5693 / Completed: 1867776 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.5693 / Completed: 1867776 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.5793 / Completed: 1900544 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.5993 / Completed: 1966080 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.5993 / Completed: 1966080 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.6093 / Completed: 1998848 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.6292 / Completed: 2064384 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.6292 / Completed: 2064384 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.6392 / Completed: 2097152 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.6592 / Completed: 2162688 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.6692 / Completed: 2195456 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.6692 / Completed: 2195456 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.6792 / Completed: 2228224 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.6991 / Completed: 2293760 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.6991 / Completed: 2293760 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.7091 / Completed: 2326528 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.7291 / Completed: 2392064 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.7291 / Completed: 2392064 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.7491 / Completed: 2457600 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.7491 / Completed: 2457600 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.7591 / Completed: 2490368 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.7691 / Completed: 2523136 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.7890 / Completed: 2588672 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.7890 / Completed: 2588672 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.7990 / Completed: 2621440 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.8090 / Completed: 2654208 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.8190 / Completed: 2686976 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.8290 / Completed: 2719744 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.8390 / Completed: 2752512 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.8490 / Completed: 2785280 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.8590 / Completed: 2818048 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.8689 / Completed: 2850816 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.8789 / Completed: 2883584 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.8889 / Completed: 2916352 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.8989 / Completed: 2949120 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.9089 / Completed: 2981888 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.9189 / Completed: 3014656 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.9389 / Completed: 3080192 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.9389 / Completed: 3080192 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.9588 / Completed: 3145728 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.9588 / Completed: 3145728 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.9688 / Completed: 3178496 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.9888 / Completed: 3244032 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 0.9888 / Completed: 3244032 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 1.0000 / Completed: 3280784 of 3280784  
  progress: 
  &lt;NSProgress: 0x28326df40&gt; : Parent: 0x0 / Fraction completed: 1.0000 / Completed: 3280784 of 3280784  
  error: 
  Optional(Error Domain=com.amazonaws.AWSS3TransferUtilityErrorDomain Code=1 "(null)" UserInfo={Server=AmazonS3, Transfer-Encoding=Identity, Connection=close, Content-Type=application/xml, Date=Wed, 27 Feb 2019 08:33:44 GMT, x-amz-request-id=B019306141A5FD4E, x-amz-id-2=nWHJCqbpTUAbNI65pNAIxzl8qXOn6y2jNg16CbvUCH/4wtqCYhVBqh86ZN6OYIV1pROSlnUA220=, x-amz-bucket-region=ap-southeast-1})
  2019-02-27 16:34:33.514453+0800 Adnexio[3854:1137756] TIC Read Status [5:0x283670300]: 1:57
  2019-02-27 16:34:33.514611+0800 Adnexio[3854:1137756] TIC Read Status [5:0x283670300]: 1:57
  2019-02-27 16:34:33.514686+0800 Adnexio[3854:1137756] TIC Read Status [5:0x283670300]: 1:57
  2019-02-27 16:34:33.517102+0800 Adnexio[3854:1137756] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C5.1:2][0x11be38fa0] get output frames failed, state 8196
  2019-02-27 16:34:33.517420+0800 Adnexio[3854:1137756] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C5.1:2][0x11be38fa0] get output frames failed, state 8196
  2019-02-27 16:34:33.518561+0800 Adnexio[3854:1137756] TIC Read Status [5:0x0]: 1:57
  2019-02-27 16:34:33.518644+0800 Adnexio[3854:1137756] TIC Read Status [5:0x0]: 1:57
  2019-02-27 16:34:33.518712+0800 Adnexio[3854:1137756] TIC Read Status [5:0x0]: 1:57
  2019-02-27 16:34:33.518786+0800 Adnexio[3854:1137756] TIC Read Status [5:0x0]: 1:57
  2019-02-27 16:34:46.805048+0800 Adnexio[3854:1137832] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C6.1:2][0x11bf10660] get output frames failed, state 8196
  2019-02-27 16:34:46.805277+0800 Adnexio[3854:1137832] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C6.1:2][0x11bf10660] get output frames failed, state 8196
  2019-02-27 16:34:46.805746+0800 Adnexio[3854:1137832] TIC Read Status [6:0x0]: 1:57
  2019-02-27 16:34:46.805802+0800 Adnexio[3854:1137832] TIC Read Status [6:0x0]: 1:57
  2019-02-27 16:34:46.875852+0800 Adnexio[3854:1138085] TIC Read Status [7:0x283662400]: 1:57
  </code></pre>
  
  <p>Somebody else had posted this and said they fixed by checking the AWS Cognito and S3 servers are in the same region. Mine was also not in the same region in the beginning but i fixed it and the error persists.</p>