How to read file from file system and send that to another URL ? Its similar to CURL request which we use in other languages.
I have tried following, but that is not working.
fs.createReadStream(files.upload.path).pipe(request.post('http://localhost/test.php', function (err, response, body) {
if (err) {
throw err;
} else {
console.log(body);
res.end();
}
}));
You have an error in your arguments. You want the callback to be sent to
request.post, notpipe:Also, it’s generally a bad idea to
throwerrors in asynchronous code.