node- create multipart request to download image

429 views Asked by At

I have in my backend a function that receives a multipart/form-data request. The function parses it using multiparty and uploads the content to S3.

const request = require('request')
const multiparty = require('multiparty');
const profile = express.Router();

profile.route('/').post(uploadImageFile);

function uploadImageFile(req, res, next){

    form.on('part', function(part) {

       let filename =  part.filename;
          /**upload file to S3 in amazon**/
    }

    var form = new multiparty.Form();
    form.on('error', function(err){
          next(err); 
    });
    form.parse(req);
}

Given an image url, I want to create a request which will call the uploadImageFile function. I need to download the url content inside the request and then send this request to uploadImageFile. I have tried something like this but with no success. My problem is that it's not a multipart request.

let download = function(uri, filename, callback) {
request.head(uri, function (err, res, body) {
    uploadImageFile(request(uri),res,callback);
})
};

download("https://lh4.googleusercontent.com/photo.jpg", "bla.png",()=> 
{ 
    console.log("done")
})
0

There are 0 answers