I’d like to download to server and then work with svg image in my app using node server as backend and React as frontend. I’ve written the following function on the server side and it works downloading the file:
const https = require('https');
const fs = require('fs');
const downloader = (url, filename) => {
https.get(url, function(res){
const fileStream = fs.createWriteStream(filename);
res.pipe(fileStream);
fileStream.on('finish', function() {
fileStream.close();
console.log('done');
})
})
};
downloader('https://www.humdes.com/local/tools/svg/?TYPE=calculation&KEY=proektor_1_3_b779c57622ad9891313a6046c1604cea', 'file.svg')
Thing is, I don’t now how to connect it to my React frontend. Say, I want to create a function that runs in ComponentDidUpdate:
downloader(this.state.imagesource, this.state.filename) {
//function that downloads file to server
}
This function must download the file using url and filename. But what must I write in downloader function to make it work with my node function?