There is a Node JS server - expressJS, which receives a picture from the POST post request. Next, you need to send this picture to another server (microservice).
I successfully receive the picture, but I cannot send it further.
Then a small code for the test, in which the first API receives a picture from the browser and immediately sends it to the second API.
package.json dependencies
"dependencies": { "lodash": "latest", "nunjucks": "latest", "redis": "latest", "connect-redis": "latest", "express": "latest", "express-session": "latest", "cookie-parser": "latest", "body-parser": "latest", "query-string": "latest", "multer": "latest", "request": "latest" } index.js
const http = require('http'); const request = require('request'); const express = require('express'); const multer = require('multer'); const bodyParser = require('body-parser'); const upload = multer(); var app = express(), server = http.createServer(app); /** * Set body parser */ app.use(bodyParser.json()); app.post('/test1', upload.single('file'), (req, req) { console.log('test1 file ->',req.file.buffer); // Here Buffer request.post( { url: 'http://localhost:3000/test2', formData: { avatar: req.file.buffer } }, (err, httpResponse, body) => { console.log(); console.log('test1 err', err); // No errors console.log('test1 body', body); // {success: true} console.log(); } ); res.json({success: true}); }); app.post('/test2', upload.single('avatar'), (req, req) { console.log('test2 file ->', req.file); // undefined console.log('test2 avatar ->', req.avatar); // undefined console.log('test2 files ->', req.files); // undefined console.log('test2 body ->', req.body); // {} res.json({success: true}); }); /** * Run server */ server.listen(3000); To send a POST request to / test2 I use npm package request In the second request I see that nothing came. If anyone encountered, specify how to do it correctly. I have so far the options are over.
PS option to save the file to disk, and then consider it fs.createReadStream is not beautiful.