Search code examples
javascriptnode.jshttp-headersnode-red

Send a multipart request from node-red to node.js


I'm failing to send files in my requests from node-red to node.js. The node.js part is working well with postman running this code :

var storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, 'uploads/')
  },
  filename: function (req, file, cb) {
    cb(null, file.fieldname + '.wav');
  }
});
var upload = multer({ storage: storage }).single('avatar');

app.post('/', function (req, res) {
  console.log(JSON.stringify(req.body));
  upload(req, res, function (err) {
    if (err) {
      res.send('failed');
    }
    res.send('Success');
  })
});

How I can set-up node-red http request to send multipart requests that will work well with the above code? I seem to find no help.


Solution

  • The built in HTTP Request node does not support multipart request.

    You need to look at the 2 options on https://flows.nodered.org:

    1. https://flows.nodered.org/node/node-red-contrib-http-request-multipart
    2. https://flows.nodered.org/node/node-red-contrib-http-multipart

    Both these contain