Webhook format problem sending json string and binary buffer

I am having trouble figuring out to exactly format a webhook (http request). I need to send a json string as well as a binary buffer. I have spent over a day trying different configurations and googling for solutions. I just cannot put the pieces together. I did seen an example where someone put the buffer under the "req" tag. But when I try that it seems as if the http request node only sends the payload.

Here is the code that I would like to work. or something similar. msg.data contains some JSON about the image.

msg.payload = msg.data;
msg.payload.image = Buffer.from(msg.image);
return msg;```

I have discovered the node-red-contrib-send-multipart-formdata node. It works great but it only takes static data. I am modifying it to take variable data. Once I am finished with that I will have my solution.

The core http request node can do formdata - no need to use a contrib node, especially one you have to modify the source of first.

The sidebar help for the request node has details under the 'file upload' section.

Thanks! This will teach me to scroll to the bottom of instructions. :slight_smile:

The sidebar is not explicit enough for me to glean how to do buffers. But I am not googling it.

I wanted to add a final note to this thread. It took me quite a while to figure it out. In my searching I got confused by the results as many are before the http request node became multipart aware. I thought I would post my final version of creating the multipart payload that finally worked for me. As a note, msg.image is a buffer array and msg.data is JSON.

msg.headers = {
    "Content-Type": "multipart/form-data"
}

msg.payload = {
    "file": {
        "value": msg.image,
        "options": {
        "Content-Type" : "application/octet-stream",
        "filename": "test"
        }
        },
    "data": {
        "value": JSON.stringify(msg.data)
    }
}
1 Like