# Send a file with multipart/form-data to OctoPrint REST API

**URL:** <https://discourse.nodered.org/t/send-a-file-with-multipart-form-data-to-octoprint-rest-api/7534>\
**Category:** General\
**Created:** [3 February 2019 18:19 UTC](https://discourse.nodered.org/t/send-a-file-with-multipart-form-data-to-octoprint-rest-api/7534 "2019-02-03T18:19:15Z")\
**Posts on this page:** 1\
**Showing post:** 15

<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:** [5 February 2019 13:29 UTC](https://discourse.nodered.org/t/send-a-file-with-multipart-form-data-to-octoprint-rest-api/7534/15 "2019-02-05T13:29:18Z")

</div>

> [@diramazioni](#):
>
> The real issue is that multipart form-data is not officially supported neither for http-in node nor for http-request.

That isn't 100% true. The HTTP In node does support file uploads now - select Post and tick the box to enable file uploads.

To send a multipart upload from the HTTP Request node is more work, but doable.

Here's a Function that will construct a suitable message to pass to the HTTP Request node:

```auto
msg.headers = {
    "Content-Type": "multipart/form-data; boundary=------------------------d74496d66958873e"
}

msg.payload = '--------------------------d74496d66958873e\r\n'+
'Content-Disposition: form-data; name="select"\r\n'+
'\r\n'+
'true\r\n'+
'--------------------------d74496d66958873e\r\n'+
'Content-Disposition: form-data; name="print"\r\n'+
'\r\n'+
'true\r\n'+
'--------------------------d74496d66958873e\r\n'+
'Content-Disposition: form-data; name="file"; filename="whistle_v2.gcode"\r\n'+
'Content-Type: application/octet-stream\r\n'+
'\r\n'+
'contents of the file\r\n'+
'--------------------------d74496d66958873e--\r\n';

return msg;

```

I've based the content from the example request you shared earlier.

A couple key points

- you need to use `\r\n` for newlines
- the boundary string set in the header defines how the separate form parts are separated in the body. When it appears in the body, it has two extra `--` in front. The very last one also has `--` added to the end. (Took quite a bit of googling and examing curl trace to spot that)

Hopefully from that you can insert the contents of the file you want to upload at the appropriate point.

---

_[View the full topic](https://discourse.nodered.org/t/send-a-file-with-multipart-form-data-to-octoprint-rest-api/7534)._
