title: stream uploading an gm-resized image to s3 with aws-sdk
body: <p>so what i want to do is to stream an image from a url, process it with graphicsmagick and stream-upload it to s3. i just dont get it working.</p>
  
  <p>streaming the processed image to local disk (using fs.createWriteStream) works without a problem. </p>
  
  <p>when i buffer my stream, the final image in s3 has at least the expected size (kb-wise), but i can not open that image.</p>
  
  <p>thats my current progress:</p>
  
  <pre><code>var request = require('request');
  
  var gm = require("gm");
  
  var AWS = require('aws-sdk');
  
  var mime = require('mime');
  
  var s3 = new AWS.S3();
  
  gm(request('http://www.some-domain.com/some-image.jpg'), "my-image.jpg")
    .resize("100^", "100^")
    .stream(function(err, stdout, stderr) {
      var str = '';
      stdout.on('data', function(data) {
         str += data;
      });
      stdout.on('end', function(data) {
        var data = {
          Bucket: "my-bucket",
          Key: "my-image.jpg",
          Body: new Buffer(str, 'binary'), // thats where im probably wrong
          ContentType: mime.lookup("my-image.jpg")
        };
        s3.client.putObject(data, function(err, res) {
          console.log("done");
        });
      });
    });
  </code></pre>
  
  <p>i did try some stuff like creating a filewritestream and filereadstream, but i think there should be some cleaner an nicer solution to that problem...</p>
  
  <p>EDIT: the first thing i tried was setting the Body to stdout (the suggested answer from @AndyD):</p>
  
  <pre><code>var data = {
      Bucket: "my-bucket",
      Key: "my-image.jpg",
      Body: stdout,
      ContentType: mime.lookup("my-image.jpg")
    };
  </code></pre>
  
  <p>but that returns following error:</p>
  
  <pre><code>Cannot determine length of [object Object]'
  </code></pre>
  
  <p>EDIT2:</p>
  
  <ul>
  <li>nodeversion: 0.8.6 (i also tried 0.8.22 and 0.10.0)</li>
  <li>aws-sdk: 0.9.7-pre.8 (installed today)</li>
  </ul>
  
  <p>the complete err:</p>
  
  <pre><code>{ [Error: Cannot determine length of [object Object]]
    message: 'Cannot determine length of [object Object]',
    object:
    { _handle:
     { writeQueueSize: 0,
      owner: [Circular],
      onread: [Function: onread] },
   _pendingWriteReqs: 0,
   _flags: 0,
   _connectQueueSize: 0,
   destroyed: false,
   errorEmitted: false,
   bytesRead: 0,
   _bytesDispatched: 0,
   allowHalfOpen: undefined,
   writable: false,
   readable: true,
   _paused: false,
   _events: { close: [Function], error: [Function: handlerr] } },
  name: 'Error' }
  </code></pre>