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(); }); });
It is unmaintainedExpress has not been updated for years, and its next version has been in alpha for 6 years. People may think it is not updated because the API is stable and does not need change.
js framework for web development. It's fast, unopinionated, and has a large community behind it. It is easy to learn and also has a lot of modules and middleware available for use. Express is used by big names like Accenture, IBM, and Uber, which means it's also great in a production environment.
What is Express JS – Quick Overview. ExpressJS is a web application framework for NodeJS. That's what mainly makes the difference between Express JS and Node JS. The former provides various features that make web application development fast and easy, which otherwise takes more time using only the latter.
Is ExpressJS frontend or backend? Express. JS is an open-source and free-to-use backend framework to develop web applications.
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
Since request
is deprecated, you can alternatively use node-fetch
like so:
app.get("/", (req, res) => { fetch(actualUrl).then(actual => { actual.headers.forEach((v, n) => res.setHeader(n, v)); actual.body.pipe(res); }); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With