nodejitsu/node-cloudfiles — Issue #32: upload binary image data from memory
Author: madhums
Created: 2012-02-28 19:57:33+00:00
State: open

Is there any way I can use the binary image data present in the memory and upload it to cloudfiles. Here is my code

```js
var form = new formidable.IncomingForm()
form.parse(req, function(err, fields, files) {
im.resize({
srcData: fs.readFileSync(files.images.path, 'binary'),
width: 256
}, function(err, stdout, stderr){
if (err) throw err

var options = {
remote: files.images.name
, headers: {
'content-type': files.images.type
}
, stream: stdout } // stdout is binary data - stream or local option would throw an error
, cdnUri = container.cdnUri

client.addFile(config.rs_container, options, onUploadToContainer)

function onUploadToContainer(err, uploaded) {
if (err) throw err
if (uploaded) res.write(cdnUri+files.images.name)
}
})
})

```
The `stdout` argument in the `im.resize` callback is binary data. `local` or `stream` option provided for `client.addFile` won't work obviously - hence an error is thrown.

I am trying not to save it as a file and then upload it to rackspace, instead I want to just use the binary data, upload to rackspace. Please correct me if I am wrong anywhere. Here is the [complete code](https://gist.github.com/1934446)