title: How can I upload files to Amazon S3 using Cordova FileTransfer?
body: <p>I'm following <a href="https://devcenter.heroku.com/articles/s3-upload-node" rel="nofollow">Heroku's tutorial</a> on direct uploads to Amazon S3.
  After getting a signed request from AWS through the Node.js app, they use a "normal" <code>XMLHttpRequest</code> to send the file.</p>
  
  <p>This is their function:</p>
  
  <pre><code>function upload_file(file, signed_request, url){
      var xhr = new XMLHttpRequest();
      xhr.open("PUT", signed_request);
      xhr.setRequestHeader('x-amz-acl', 'public-read');
      xhr.onload = function() {
          if (xhr.status === 200) {
              document.getElementById("preview").src = url;
              document.getElementById("avatar_url").value = url;
          }
      };
      xhr.onerror = function() {
          alert("Could not upload file.");
      };
      xhr.send(file);
  }
  </code></pre>
  
  <p>Now, I'm working with Cordova and, since I don't get a <code>File</code> object from the camera plugin, but only the file URI, I used Cordova's <a href="https://github.com/apache/cordova-plugin-file-transfer" rel="nofollow"><code>FileTransfer</code></a> to upload pictures to my Node.js app with <code>multipart/form-data</code> and it worked fine.</p>
  
  <p>However, I can't manage to make it work for Amazon S3.</p>
  
  <p>Here's what I have:</p>
  
  <pre><code>$scope.uploadPhoto = function () {
      $scope.getSignedRequest(function (signedRequest) {
          if (!signedRequest)
              return;
  
          var options = new FileUploadOptions();
          options.fileKey = 'file';
          options.httpMethod = 'PUT';
          options.mimeType = 'image/jpeg';
          options.headers = {
              'x-amz-acl': 'public-read'
          };
          options.chunkedMode = false;
  
          var ft = new FileTransfer();
          ft.upload($scope.photoURI, encodeURI(signedRequest.signed_request), function () {
              // success
          }, function () {
              // error
          }, options);
      });
  };
  </code></pre>
  
  <p>I've tried both <code>chunkedMode = true</code> and <code>chunkedMode = false</code>, but neither the success nor the error callback is called.</p>
  
  <p>So, is there a way to upload a file to S3 with <code>FileTransfer</code>?
  Do I actually need the signed request or is it only necessary if I use XHR?</p>
  
  <p>Any hint is appreciated.</p>