Search code examples
node.jsfile-uploadwatchnode-red

Watch folder for created file and upload created file to server using Node RED


Goal

I want to watch folder using node red. If any file created then I want to upload that file to server using node red http request node.

I have used node-red-contrib-wfwatch module for folder watch and http request module for api call.

Issue

I am able to get change event on file created but how can i pass select file to http request body as form data. I have no idea how to do it.

I am new in Node Red so can anyone please help for achieve this.

Here what I want to achieve

Structure of Node red display here


Solution

  • The node-red-contrib-wfwatch node doesn't get the file, just sends a message with following payload:

    {
      changeType: "update",
      filePath: "/tmp/foo"
    }
    

    You need to use File node for this purpose. But before that, because the File node expects the filename be in msg.filename not in msg.payload.filePath you need to add Change node:

    and connect the whole thing like this:

    Just replace the Debug node with your HTTP Request one.