diff --git a/packages/node_modules/@node-red/nodes/core/io/21-httprequest.js b/packages/node_modules/@node-red/nodes/core/io/21-httprequest.js index dae51ded7..45e053f46 100644 --- a/packages/node_modules/@node-red/nodes/core/io/21-httprequest.js +++ b/packages/node_modules/@node-red/nodes/core/io/21-httprequest.js @@ -203,28 +203,32 @@ module.exports = function(RED) { var payload = null; if (method !== 'GET' && method !== 'HEAD' && typeof msg.payload !== "undefined") { - if (typeof msg.payload === "string" || Buffer.isBuffer(msg.payload)) { - payload = msg.payload; - } else if (typeof msg.payload == "number") { - payload = msg.payload+""; + if (opts.headers['content-type'] == 'multipart/form-data' && typeof payload === "object") { + opts.formData = msg.payload; } else { - if (opts.headers['content-type'] == 'application/x-www-form-urlencoded') { - payload = querystring.stringify(msg.payload); + if (typeof msg.payload === "string" || Buffer.isBuffer(msg.payload)) { + payload = msg.payload; + } else if (typeof msg.payload == "number") { + payload = msg.payload+""; } else { - payload = JSON.stringify(msg.payload); - if (opts.headers['content-type'] == null) { - opts.headers[ctSet] = "application/json"; + if (opts.headers['content-type'] == 'application/x-www-form-urlencoded') { + payload = querystring.stringify(msg.payload); + } else { + payload = JSON.stringify(msg.payload); + if (opts.headers['content-type'] == null) { + opts.headers[ctSet] = "application/json"; + } } } - } - if (opts.headers['content-length'] == null) { - if (Buffer.isBuffer(payload)) { - opts.headers[clSet] = payload.length; - } else { - opts.headers[clSet] = Buffer.byteLength(payload); + if (opts.headers['content-length'] == null) { + if (Buffer.isBuffer(payload)) { + opts.headers[clSet] = payload.length; + } else { + opts.headers[clSet] = Buffer.byteLength(payload); + } } + opts.body = payload; } - opts.body = payload; } if (method == 'GET' && typeof msg.payload !== "undefined" && paytoqs) { diff --git a/packages/node_modules/@node-red/nodes/locales/en-US/io/21-httprequest.html b/packages/node_modules/@node-red/nodes/locales/en-US/io/21-httprequest.html index aa027da2e..bbe66e07b 100644 --- a/packages/node_modules/@node-red/nodes/locales/en-US/io/21-httprequest.html +++ b/packages/node_modules/@node-red/nodes/locales/en-US/io/21-httprequest.html @@ -78,5 +78,18 @@

If msg.payload is an Object, the node will automatically set the content type of the request to application/json and encode the body as such.

To encode the request as form data, msg.headers["content-type"] should be set to application/x-www-form-urlencoded.

+

File Upload

+

To perform a file upload, msg.headers["content-type"] should be set to multipart/form-data + and the msg.payload passed to the node must be an object with the following structure:

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

The values of KEY, FILE_CONTENTS and FILENAME + should be set to the appropriate values.