0

I am using request npm module. I have a gateway which acts as the middle man, takes request from outside and forwards it to the concerned microservice. For downloads, I have the following code.

if (
    req.baseUrl.match('download') ||
    req.url.match('download')
) {
    request.get(url).pipe(res);
    return;
}

Now I have to upload image to a microservice, how do I do that, I am clueless.

zegulas
  • 417
  • 2
  • 6
  • 18
  • 1
    I'm not sure I understand your question completely, your should add more info about any frameworks you are using? how do you communicate with your micro services? etc. Having said that, here's a good general direction: For uploads you can use multer [link](https://github.com/expressjs/multer) it's pretty simple to understand from the docs. After you get the file to your server using multer, you can then forward it to your micro services or store it in your data store and just forward it's uid and download it from the micro services then passing it back to the gateway. – ChicoDelaBarrio Dec 27 '17 at 14:45

1 Answers1

0

This worked for me.

req.pipe(request('http://host/url/')).pipe(res)
zegulas
  • 417
  • 2
  • 6
  • 18