Skip to content

Instantly share code, notes, and snippets.

@thebigbad
Forked from bxjx/gist:583836
Created October 29, 2010 20:05
Show Gist options
  • Save thebigbad/654299 to your computer and use it in GitHub Desktop.
Save thebigbad/654299 to your computer and use it in GitHub Desktop.
var express = require('express'),
request = require('request'),
BufferList = require('bufferlist').BufferList,
sys = require('sys');
var app = express.createServer(
express.logger(),
express.bodyDecoder()
);
app.get('/', function(req, res){
if(req.param("url")) {
var url = unescape(req.param("url"));
var bl = new BufferList();
request({uri:url, responseBodyStream: bl}, function (error, response, body) {
if (!error && response.statusCode == 200) {
var data_uri_prefix = "data:" + response.headers["content-type"] + ";base64,";
var image = new Buffer(bl.toString(), 'binary').toString('base64');
image = data_uri_prefix + image;
res.send('<img src="'+image+'"/>');
}
});
}
});
app.listen(3010);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment