Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
23
rated 0 times [  30] [ 7]  / answers: 1 / hits: 32147  / 11 Years ago, sun, august 25, 2013, 12:00:00

I would like to read a remote image and display it. I can save the file but not getting the code right to display it. Ideally I just want to pass the file right though without processing - not sure if a tmp file step is required or not. This code displays nothing - no errors. I tried res.pipe(response) as well.



var url = 'http://proxy.boxresizer.com/convert?resize=50x50&source=' + filename

var request = http.get(url, function(response) {

var tmp = path.join(require('os').tmpDir(), filename);

var outstream = require('fs').createWriteStream(tmp);

response.pipe(outstream);
response.on('end', function() {
res.set('Content-Type', 'image/jpg');
res.pipe(outstream);
res.end();
});
});

More From » node.js

 Answers
6

Well I'd still like to know how to make the above work but I solved my issue in one line with the request module!



var url = 'http://proxy.boxresizer.com/convert?resize=50x50&source=' + filename
require('request').get(url).pipe(res); // res being Express response

[#76140] Saturday, August 24, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mickaylag

Total Points: 333
Total Questions: 108
Total Answers: 93

Location: Solomon Islands
Member since Fri, Oct 8, 2021
3 Years ago
;