Uploading multiple files at once

Hello good folks,

I am trying to upload multiple files at once, from Node-RED to another server, using the HTTP Request Node. The documentation explains the payload structure required to attach a single file:

{
    "KEY": {
        "value": FILE_CONTENTS,
        "options": {
            "filename": "FILENAME"
        }
    }
}

This works when I need to upload a single file, but what about multiple files?

Here's the architecture of my system:

  • SERVER 1 submits, through a single HTTP request, one or more files to Node-RED
  • Node-RED captures these files with the HTTP In node and forwards them to SERVER 2 using the HTTP Request node. All files must be embedded into that single HTTP Request.
  • SERVER 2 processes the files and responds with a summary of the processing information to Node-Red
  • Node-RED then simply sends back the response to SERVER 1

I unfortunately have no control over either SERVER 1 or SERVER 2, so I cannot change the way they send/process files.

So in summary, I need all files received as a group to be forwarded as a group to the destination server so it can aggregate data pulled from all attachments it receives in a single transaction.

Judging from the JSON structure above, this isn't possible. Are there alternatives to the HTTP Request node for this specific use case?

Thanks

Well it looks like I answered my own question after digging through the code for the HTTP Request node: there can be as many "KEY" properties as you want in the payload structure:

{
    "File1": {
        "value": "some file content",
        "options": {
            "filename": "MyFirstFile.txt"
        }
    },
    "File2": {
        "value": "some other content",
        "options": {
            "filename": "MySecondFile.txt"
        }
    }
}

I personally think it would have been more explicit if the payload contained an array instead of distinct properties, but hey, what do I know?!? :slight_smile:

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.