# Add support for multipart/form-data in request node

**URL:** <https://discourse.nodered.org/t/add-support-for-multipart-form-data-in-request-node/8111>\
**Category:** Core Development\
**Created:** [18 February 2019 17:00 UTC](https://discourse.nodered.org/t/add-support-for-multipart-form-data-in-request-node/8111 "2019-02-18T17:00:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kastentx](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kastentx/32/5582_2.png) [@kastentx](https://discourse.nodered.org/u/kastentx)\
**Post date:** [18 February 2019 17:00 UTC](https://discourse.nodered.org/t/add-support-for-multipart-form-data-in-request-node/8111/1 "2019-02-18T17:00:06Z")

</div>

Hi all, I've been working on adding support for `multipart/form-data` type data in POST requests with the stanard `http request` node.

Currently, I have it working with this type of message going into the `http request` node.

```javascript
var fileData = msg.payload;
msg.headers = {'Content-Type': 'multipart/form-data'};

msg.payload = {
    'image' : {
        'value': fileData,
        'options': {
            'filename': 'image.png'
        }
    }
};

return msg;

```

Any feedback on this? If it looks good, I can go ahead and open a pull request on gitHub or work on some supporting documentation.

---

<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:** [19 February 2019 16:56 UTC](https://discourse.nodered.org/t/add-support-for-multipart-form-data-in-request-node/8111/2 "2019-02-19T16:56:28Z")

</div>

Hi @kastentx

that looks good. Presumably the key thing here is for the `content-type` header to be set to `multipart/form-data` and that `msg.payload` is then an object of key/value pairs to use as the form data.

It is possible that flows will exist that set the content-type header to `multipart/form-data` and that also construct the required payload from scratch, so `msg.payload` will be a Buffer or String. In those cases, we should make sure they pass through as-is so those flows continue to work.

---

<div class="post-metadata">

**Author:** ![kastentx](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kastentx/32/5582_2.png) [@kastentx](https://discourse.nodered.org/u/kastentx)\
**Post date:** [20 February 2019 16:15 UTC](https://discourse.nodered.org/t/add-support-for-multipart-form-data-in-request-node/8111/3 "2019-02-20T16:15:34Z")

</div>

Thank you @knolleary!

I've gone ahead and added another conditional check to the relevant section in `21-httprequest.js`. I thought about checking for something NOT typeof String or Buffer, but thought it might also be a good place to just check for an Object. This should allow strings, buffers, and numbers to pass through unaffected by the change.

Here's that part of code with the check:

```javascript
if (method !== 'GET' && method !== 'HEAD' && typeof msg.payload !== "undefined") {
                if (opts.headers['content-type'] == 'multipart/form-data' && typeof payload === "object") {
                    opts.formData = msg.payload;
                } else {
        ...
        ...

```
