javascript 在 ExpressJS 中管道远程文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18432779/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Piping remote file in ExpressJS
提问by cyberwombat
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.
我想读取远程图像并显示它。我可以保存文件,但没有正确显示代码。理想情况下,我只想在不处理的情况下直接传递文件 - 不确定是否需要 tmp 文件步骤。此代码不显示任何内容 - 没有错误。我也试过 res.pipe(response) 。
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();
});
});