Created
June 10, 2011 06:56
-
-
Save beaucollins/1018358 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var http = require('http'); | |
var url = require('url'); | |
var sys = require('sys'); | |
var file = './hyperdrive.jpg'; | |
var blogId = 10231312; | |
var username = 'redacted'; | |
var password = 'redacted'; | |
var endpoint = 'http://example.com'; | |
var destination = url.parse(endpoint); | |
if(file){ | |
var read = fs.createReadStream(file, { flags: 'r', encoding: null, mode: 0666, bufferSize:1024 }); | |
var local = http.createClient((destination.port || 80), destination.hostname); | |
var request = local.request('POST', destination.pathname, { | |
'User-Agent' : 'webOS Bitches' | |
}); | |
var front = '<?xml version="1.0" ?><methodCall><methodName>wp.uploadFile</methodName>'; | |
front += '<params>'; | |
front += '<param><int>' + blogId + '</int></param>'; | |
front += '<param><string>' + username + '</string></param>'; | |
front += '<param><string>' + password + '</string></param>'; | |
front += '<param><base64>'; | |
var back = '</base64></param></params></methodCall>'; | |
request.write(front); | |
read.setEncoding('base64'); | |
request.on('drain', function(){ | |
read.resume(); | |
}); | |
read.on('data', function(data){ | |
if(!write.write(data)){ | |
read.pause(); | |
} | |
}); | |
read.on('error', function(exception){ | |
future.result = exception; | |
future.returnValue = false; | |
}); | |
read.on('end', function(){ | |
request.write(back); | |
request.end(); | |
}); | |
request.on('response', function(response){ | |
response.on('end', function(){ | |
var result = { status: response.statusCode }; | |
console.log(result); | |
}) | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment