title: Unable to upload image blob to AWS S3 using node.js & angular
body: <p>I am unable to upload my images to AWS S3 </p>
  
  <blockquote>
    <p>{ [InvalidParameterType: Expected params.Body to be a string, Buffer,
    Stream, Blob, or typed array object]  message: 'Expected params.Body
    to be a string, Buffer, Stream, Blob, or typed array object',  code:
    'InvalidParameterType',</p>
  </blockquote>
  
  <p><strong>Background</strong>
  So this is what I am trying to do: first, I used Angular Image Cropper (<a href="http://andyshora.com/angular-image-cropper.html" rel="nofollow">http://andyshora.com/angular-image-cropper.html</a>) to crop the image to a acceptable size for mobile. This gives a base64 URI.</p>
  
  <p>Then, I used dataURItoBlob to convert the URI to blob, and attempt to upload to AWS S3.</p>
  
  <p>The code looks like this:</p>
  
  <p><strong>Angular</strong></p>
  
  <pre><code>$scope.dataURItoBlob= function(dataURI) {
      var binary = atob(dataURI.split(',')[1]);
      var array = [];
      for(var i = 0; i &lt; binary.length; i++) {
          array.push(binary.charCodeAt(i));
      }
      return new Blob([new Uint8Array(array)], {type: 'image/png'});
  }
  
  
  $scope.uploadPic = function() {
      var base64data = document.getElementById('base64').value;
  
      console.log("the data is: "+ base64data);
      $scope.pic.Body = $scope.dataURItoBlob(base64data);
      console.log("the blob is: "+ $scope.pic.Body);
  
      $http({
      method: 'POST',
      url: '/api/upload/picture',
      data: $scope.pic
    }).success(function (data) {
      //success code
    });
  
  };  
  </code></pre>
  
  <p><strong>Node (backend)</strong></p>
  
  <pre><code>exports.uploadPicture = function (req, res) {
          if (!req.body.hasOwnProperty('Key') || !req.body.hasOwnProperty('Body')) {
              res.statusCode = 400;
              return res.send('Error 400: Post syntax incorrect.');
          } else {
              var key = req.body.Key;
              var body = req.body.Body;
  
              AWS.config.loadFromPath('./config.json');
  
              var s3 = new AWS.S3(); 
              s3.createBucket({Bucket: 'bucket'}, function() {
                var params = {Bucket: 'bucket', Key: key, Body: body};
                s3.putObject(params, function(err, data) {
                if (err) {
                console.log(err);
                  res.status(400).send('Bad Request.');
                } else {
                  console.log("Successfully uploaded data to myBucket/myKey");   
                }
              });
              });
          }
  
  }
  </code></pre>
  
  <p>It fails because it is expecting a Blob but it is rejecting the Blob that I am sending in.. Please help!</p>
  
  <p>Thanks!</p>