CURL implementation in node red

trying to implement this curl request in node red stuck on how to do the -F parts

curl -i -X POST -H “Content-Type: multipart/form-data” -F “upload=@/Users/al/artwork/pacman.gif” -F “upload-type=ANIMATED_GIF” -F “console=MAME” -F “displaynow=1” http://localhost:8080/uploadplatform

What nodes are you using?
when you say you are stuck on the -F parts - what do you mean?
What have you done so far?

I take it as meaning he wants to POST form data in node-red (and that curl is a working example)

@4_fools try making a JS object with your form properties and values as key/value pairs and pass that into the http request node as msg.payload

I have tried following this picture which I believe you posted a while ago

https://global.discourse-cdn.com/business6/uploads/nodered/original/3X/9/c/9cf6a6286527af2ddbcc7863642f99995c0d27a9.png

I am sorry but I do not understand what this means
"JS object with your form properties and values as key/value pairs"

The is pretty basic JavaScript knowledge - you would do well to learn some JavaScript (especially about objects and JSON - it will help you get to grips with node red as will watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red.


A JS object is created like this...

var myObject = {}; //create an empty object
myObject.myNumberProperty = 123; // add a number property
var theNumber = myObject.myNumberProperty; //how to access a property in an object

So where i said "try making a JS object with your form properties and values as key/value pairs" you would do something like this...

/* working curl...
curl -i -X POST -H “Content-Type: multipart/form-data” -F “upload=@/Users/al/artwork/pacman.gif” -F “upload-type=ANIMATED_GIF” -F “console=MAME” -F “displaynow=1”
*/

//set msg.headers to an {object} with property "Content-Type" set to "multipart/form-data"
msg.headers = {
    "Content-Type": "multipart/form-data" 
}
    
//set payload to an {object} with key/values as specified in the curl form data
msg.payload = {
        "upload": "@/Users/al/artwork/pacman.gif",
        "upload-type": "ANIMATED_GIF",
        "console": "MAME",
        "displaynow": 1
};  

//set url
msg.url = "http://localhost:8080/uploadplatform"

// return the msg to next node (the http request)
return msg;

NOTE: the msg.url property can be set in the function or in the http request node (read the built in help on the RH side-bar)

Here is a demo flow you can import (untested - as i dont have your endpoint or flow - but it should get you close)

[{"id":"bb7f1af3.ad7df8","type":"function","z":"553814a2.1248ec","name":"","func":"/* working curl...\ncurl -i -X POST -H “Content-Type: multipart/form-data” -F “upload=@/Users/al/artwork/pacman.gif” -F “upload-type=ANIMATED_GIF” -F “console=MAME” -F “displaynow=1”\n*/\n\n//set msg.headers to an {object} with property \"Content-Type\" set to \"multipart/form-data\"\nmsg.headers = {\n    \"Content-Type\": \"multipart/form-data\" \n}\n    \n//set payload to an {object} with properties and values\nmsg.payload = {\n        \"upload\": \"@/Users/al/artwork/pacman.gif\",\n        \"upload-type\": \"ANIMATED_GIF\",\n        \"console\": \"MAME\",\n        \"displaynow\": 1\n};  \n\n//set url\nmsg.url = \"http://localhost:8080/uploadplatform\"\n\n// return the msg to next node (the http request)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1500,"y":1040,"wires":[["2a16909e.64bbf"]]},{"id":"e2e9f5bb.79a668","type":"inject","z":"553814a2.1248ec","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1340,"y":1040,"wires":[["bb7f1af3.ad7df8"]]},{"id":"2a16909e.64bbf","type":"http request","z":"553814a2.1248ec","name":"","method":"POST","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":1670,"y":1040,"wires":[["4209b9dd.0c7928"]]},{"id":"4209b9dd.0c7928","type":"debug","z":"553814a2.1248ec","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1850,"y":1040,"wires":[]}]
1 Like

Thank you I will go though some of the tutorials

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