# Webhook format problem sending json string and binary buffer

**URL:** <https://discourse.nodered.org/t/webhook-format-problem-sending-json-string-and-binary-buffer/54219>\
**Category:** General\
**Created:** [24 November 2021 17:23 UTC](https://discourse.nodered.org/t/webhook-format-problem-sending-json-string-and-binary-buffer/54219 "2021-11-24T17:23:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmorris644](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jmorris644/32/31964_2.png) [@jmorris644](https://discourse.nodered.org/u/jmorris644)\
**Post date:** [24 November 2021 17:23 UTC](https://discourse.nodered.org/t/webhook-format-problem-sending-json-string-and-binary-buffer/54219/1 "2021-11-24T17:23:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jmorris644](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jmorris644/32/31964_2.png) [@jmorris644](https://discourse.nodered.org/u/jmorris644)\
**Post date:** [24 November 2021 20:19 UTC](https://discourse.nodered.org/t/webhook-format-problem-sending-json-string-and-binary-buffer/54219/2 "2021-11-24T20:19:37Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![jmorris644](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jmorris644/32/31964_2.png) [@jmorris644](https://discourse.nodered.org/u/jmorris644)\
**Post date:** [24 November 2021 21:11 UTC](https://discourse.nodered.org/t/webhook-format-problem-sending-json-string-and-binary-buffer/54219/3 "2021-11-24T21:11:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [24 November 2021 21:26 UTC](https://discourse.nodered.org/t/webhook-format-problem-sending-json-string-and-binary-buffer/54219/4 "2021-11-24T21:26:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jmorris644](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jmorris644/32/31964_2.png) [@jmorris644](https://discourse.nodered.org/u/jmorris644)\
**Post date:** [24 November 2021 21:53 UTC](https://discourse.nodered.org/t/webhook-format-problem-sending-json-string-and-binary-buffer/54219/5 "2021-11-24T21:53:14Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![jmorris644](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jmorris644/32/31964_2.png) [@jmorris644](https://discourse.nodered.org/u/jmorris644)\
**Post date:** [25 November 2021 15:00 UTC](https://discourse.nodered.org/t/webhook-format-problem-sending-json-string-and-binary-buffer/54219/7 "2021-11-25T15:00:12Z")

</div>

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.

```auto
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)
    }
}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [24 January 2022 15:00 UTC](https://discourse.nodered.org/t/webhook-format-problem-sending-json-string-and-binary-buffer/54219/8 "2022-01-24T15:00:58Z")

</div>

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