Upload file to Synology Filestation over API (one more try)

According to that document, you need to create a multipart form-data POST.

The built in docs of the HTTP Request node explain what headers and values you need to send.

Here is an (untested) example...

image

Flow (use CTRL-I to import)

[{"id":"2b377364e1c38834","type":"http request","z":"55525a9d18c99b86","name":"","method":"POST","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"headers":[],"x":650,"y":1060,"wires":[[]]},{"id":"2afa22ddfca54482","type":"inject","z":"55525a9d18c99b86","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":285,"y":1000,"wires":[["2ac84dacdaa772d5"]],"l":false},{"id":"5e7d5463bdc5ef3f","type":"file in","z":"55525a9d18c99b86","name":"Get file \"filename\"","filename":"filename","filenameType":"msg","format":"","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":770,"y":1000,"wires":[["5b885fa382a4078e"]]},{"id":"5b885fa382a4078e","type":"function","z":"55525a9d18c99b86","name":"Create multipart/form-data","func":"//set  my.syno.nas.ip  to IP or HOSTNAME of NAS\nmsg.url = \"http://my.syno.nas.ip/webapi/entry.cgi\";\n\nmsg.headers = {\n    \"content-type\": \"multipart/form-data\"\n}\n\nmsg.payload = {\n    \"api\": \"SYNO.FileStation.Upload\",\n    \"version\": \"2\",\n    \"method\": \"upload\",\n    \"path\": msg.uploadPath,//where to put file on nas\n    \"create_parents\": \"true\",\n    \"file\": {\n        \"value\": msg.payload, //file buffer\n        \"options\": {\n            \"filename\": msg.uploadFilename  //write to nas as this name\n        }\n    }\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":430,"y":1060,"wires":[["2b377364e1c38834"]]},{"id":"2ac84dacdaa772d5","type":"change","z":"55525a9d18c99b86","name":"setup filename, uploadPath, uploadFilename","rules":[{"t":"set","p":"filename","pt":"msg","to":"c:/temp/test.txt","tot":"str"},{"t":"set","p":"uploadPath","pt":"msg","to":"/data/temp","tot":"str"},{"t":"set","p":"uploadFilename","pt":"msg","to":"test.txt","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":1000,"wires":[["5e7d5463bdc5ef3f"]]}]

You will need to open the "setup filename" and "create multipart" nodes & set the variables accordingly.

Good luck

1 Like