I want to download a image file to server first, then upload this file to other server.
If there is no download file step
, it will be very simple
Following the request
documentation, you can use
request.get(sourceUrl).pipe(request.post(targetUrl))
in this scheme, the data will flow from sourceUrl to targetUrl but will not need to be saved in a temporary file on the server.
cf https://github.com/request/request#streaming for more details.
This works for me:
var fs = require('fs');
var request = require('request');
var formData = {
method : 'POST',
url : 'http://127.0.0.1:3000',
json : true,
formData : { file : request(downloadUrl) }
};
request(formData, function(err, res, body){
if (err) throw err;
console.log("successful");
});