title: Cordova/Ionic app uploading base64 image to S3 via server signed url
body: <p>I can't seem to get the photo to upload on S3. Looked at a lot of resources online and I can't seem to find a definite answer to this. Here's what I have so far. I always get Error code: 3 as my failed message.</p>
  
  <p>Client side:</p>
  
  <pre><code>$scope.uploadTopicPhoto = function(imageData) {
      var image2save = "data:image/jpeg;base64," + imageData;
      $http({
        url: 'http://api.example.io/signS3upload', 
        method: "GET"
       }).then(function (success) {
          var options = new FileUploadOptions();
          options.fileKey = "file";
          options.fileName = success.data.key
          options.mimeType = "image/jpeg";    
          options.chunkedMode = false;
          options.httpMethod = 'PUT';
  
          function win(r) {
              console.log("Code = " + r.responseCode);
          }
  
          function fail(error) {
              alert("An error has occurred: Code = " + error.code);
          }
  
          var uri = encodeURI(success.data.signed_request);
  
          var ft = new FileTransfer();
          ft.upload(image2save, uri, win, fail, options);
       });
  }
  </code></pre>
  
  <p>Server side:</p>
  
  <pre><code>var s3 = new aws.S3();
      var bucketName = 'testimages';
      var s3_params = {
          Bucket: bucketName,
          Key: uuid.v4() + '.jpg',
          Expires: 60,
          ContentEncoding: 'base64',
          ContentType: 'image/jpeg',
          ACL: 'public-read'
      };
  
      s3.getSignedUrl('putObject', s3_params, function(err, data){
          if (err) {
              console.log(err);
          } else {
          var return_data = {
              signed_request: data,
              key: s3_params.Key
          };
          res.json(return_data);
          }
  });
  </code></pre>
  
  <p>CORS:</p>
  
  <pre><code>&lt;CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"&gt;
      &lt;CORSRule&gt;
          &lt;AllowedOrigin&gt;*&lt;/AllowedOrigin&gt;
          &lt;AllowedMethod&gt;GET&lt;/AllowedMethod&gt;
          &lt;AllowedMethod&gt;PUT&lt;/AllowedMethod&gt;
          &lt;AllowedMethod&gt;POST&lt;/AllowedMethod&gt;
          &lt;AllowedMethod&gt;DELETE&lt;/AllowedMethod&gt;
          &lt;MaxAgeSeconds&gt;3000&lt;/MaxAgeSeconds&gt;
          &lt;AllowedHeader&gt;Content-*&lt;/AllowedHeader&gt;
          &lt;AllowedHeader&gt;Authorization&lt;/AllowedHeader&gt;
          &lt;AllowedHeader&gt;*&lt;/AllowedHeader&gt;
      &lt;/CORSRule&gt;
  &lt;/CORSConfiguration&gt;
  </code></pre>