Hello there,
I'm having a hard time configuring the nodes correctly in order to send an uploaded file to OctoPrint REST. Here is my node setup however i't won't work unless you register your app in your local octoprint and get an API key to be set in the attached flow. (ops I'm new and I can't)
[{"id":"d601341.b493c48","type":"change","z":"9b9a811f.0afc7","name":"set payload","rules":[{"t":"set","p":"filename","pt":"msg","to":"req.files['file'][0].path","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":2780,"wires":[["9f9cdcaf.bba298","131edc7f.8c3e4c","665a2eec.c1dd7"]]},{"id":"9f9cdcaf.bba298","type":"change","z":"9b9a811f.0afc7","name":"API-key","rules":[{"t":"set","p":"headers","pt":"msg","to":"{\"X-Api-Key\":\"xxxSetYourKey\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":2780,"wires":[["6f15e914.283a4"]]},{"id":"2701ee04.a0bf52","type":"httpInMultipart","z":"9b9a811f.0afc7","name":"","url":"/octopi-upload","method":"post","fields":"[{\"name\": \"file\", \"maxCount\": 1}, {\"filename\":\"\"}]","swaggerDoc":"","x":130,"y":2780,"wires":[["d601341.b493c48"]]},{"id":"131edc7f.8c3e4c","type":"debug","z":"9b9a811f.0afc7","name":"","active":true,"tosidebar":true,"console":false,"complete":"req.files","x":550,"y":2700,"wires":[]},{"id":"665a2eec.c1dd7","type":"file in","z":"9b9a811f.0afc7","name":"","filename":"","format":"","chunk":false,"sendError":false,"x":330,"y":2900,"wires":[["377c8d6c.890e42"]]},{"id":"6f15e914.283a4","type":"function","z":"9b9a811f.0afc7","name":"Set Headers","func":"var file = msg.req.files['file'][0];\n\nmsg.headers = {};\n//msg.headers['Accept'] = 'application/json';\nmsg.headers['Content-Type']= 'multipart/form-data';\nmsg.headers['Content-Disposition']= `form-data; name=\"file\"; filename=${file.originalname}`\n\nmsg.form={}\nmsg.payload[\"file\"]=\"data:application/octet-stream;base64,${msg.payload.toString('base64')}\";\n//msg.payload;\n// \n\n\nreturn msg;","outputs":1,"noerr":0,"x":590,"y":2840,"wires":[["1e8ff8d3.b58997","f601f775.0cfab8"]]},{"id":"377c8d6c.890e42","type":"base64","z":"9b9a811f.0afc7","name":"","action":"","property":"payload","x":480,"y":2880,"wires":[["6f15e914.283a4"]]},{"id":"1e8ff8d3.b58997","type":"http request","z":"9b9a811f.0afc7","name":"to OctoPi POST /api/files/(string: location) ","method":"POST","ret":"txt","url":"192.168.1.5/api/files/local","tls":"","x":860,"y":2840,"wires":[["920a3e9d.04e958","495b41ca.5d1878"]]},{"id":"f601f775.0cfab8","type":"debug","z":"9b9a811f.0afc7","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":870,"y":2720,"wires":[]},{"id":"920a3e9d.04e958","type":"debug","z":"9b9a811f.0afc7","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1070,"y":2780,"wires":[]},{"id":"495b41ca.5d1878","type":"http response","z":"9b9a811f.0afc7","name":"response","statusCode":"200","headers":{},"x":1090,"y":2920,"wires":[]},{"id":"c25041d2.d8bd88","type":"ui_template","z":"9b9a811f.0afc7","group":"e97f66fe.f451c","name":"upload Template","order":2,"width":0,"height":0,"format":"\n <form id=\"fileUpload\" action=\"/octopi-upload\" method=\"post\" enctype=\"multipart/form-data\">\n <input type=\"file\" name=\"file\" id=\"fileToUpload\">\n <input type=\"submit\" value=\"upload gcode\" name=\"submit\" \n style=\"background-color: chartreuse;\"\n class=\"form-button\">\n </form>\n ","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":330,"y":2680,"wires":[[]]},{"id":"e97f66fe.f451c","type":"ui_group","z":"","name":"Files","tab":"81b4005b.665ae8","order":5,"disp":true,"width":"6","collapse":true},{"id":"81b4005b.665ae8","type":"ui_tab","z":"9b9a811f.0afc7","name":"3DPrint","icon":"camera_alt","order":2,"disabled":false,"hidden":false}]
I'll describe it briefly so you don't actually have to install octopi to help me out
In the flow an UI-template post a file using the httpInMultipart node endpoint. in msg.req.files there are the pointer to the temporary file like /tmp/1f9fbd1f8967f1c6cccbf2bbb483f45a
the get correctly created.
This path is available under req.files['file'][0].path and since the File-in
node it requires msg.filename I've set a change node
for that.
The the common API-key header get set (you need yours) and the required headers for the OctoPi REST API for file upload get set in the Set Headers function node before being sent to the http request node.
I think OctoPi doesn't like they way I'm sending it as data:application/octet-stream;base64 in msg.payload["file"]
I'm sending the payload of the File_in node with the correct real path!!!
Unfortunately the 400 Bad request error as a response from octopi is not really helpful and I don't know where to go from here
I've easily built an entire panel controlling and monitoring Octopy in node-red only the file upload is not working... can you help me out?
dashboard screenshot