Mark Boon
Mark Boon

Reputation: 13

node-red upload attachment over http

Breaking my head a bit around this. The ootb HTTP request support HTTP POST; very well usable for form data. However I cannot get this to work with upload a local file (octet-stream). Any examples available?

regards, Mark

Upvotes: 0

Views: 2446

Answers (1)

hardillb
hardillb

Reputation: 59731

You should just need to set the content-type header before passing the file into the http-request node.

You can use a change node to do this.

The following flow reads a file from disk, and uploads it to a URL.

[{"id":"a6e812ac.d1a3c8","type":"http request","z":"83ca60e.03443a","name":"","method":"POST","ret":"txt","url":"http://localhost:1880/file","tls":"","x":700.5,"y":406,"wires":[["1bdd769.2f63309"]]},{"id":"a72b1e78.9cadf","type":"inject","z":"83ca60e.03443a","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":144.5,"y":367,"wires":[["79844828.9aad18"]]},{"id":"79844828.9aad18","type":"file in","z":"83ca60e.03443a","name":"","filename":"/opt/share/playing/opencv/crop.jpeg","format":"","x":361.5,"y":403,"wires":[["95401938.2085b8"]]},{"id":"95401938.2085b8","type":"change","z":"83ca60e.03443a","name":"","rules":[{"t":"set","p":"header","pt":"msg","to":"{\"content-type\": \"application/octet-stream\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":591.5,"y":348,"wires":[["a6e812ac.d1a3c8"]]},{"id":"1bdd769.2f63309","type":"debug","z":"83ca60e.03443a","name":"","active":true,"console":"false","complete":"false","x":836.5,"y":352,"wires":[]}]

Upvotes: 1

Related Questions