Node Red post an image to Deepstack

I’m not sure if anyone can help me here but I am looking to post an image to Deepstack directly from Node Red, does anyone happen to have a working example? I have tried so many permutations of the http request object and associated function / headers / etc and the only thing I get back from Deepstack is “{“success”:false,“error”:“No valid image file found”}”. Any assistance would be greatly appreciated!

Hi uproden,

be careful from where the image comes from. It may be base64 encoded! I have an example here, where I receive the image and a message as a mqtt payload. So I first need to decode it with base64, then build the form data and finally send a POST request. Hope it helps:

[{"id":"807297c4.04fbf8","type":"mqtt in","z":"58014e9a.6e855","name":"","topic":"CameraEvents/Dahua1/Image","qos":"2","datatype":"json","broker":"ccee1e48.2c6ca","x":140,"y":340,"wires":[["5a1a945a.18f69c","d39ba014.14019","fb89ae81.f2c83"]]},{"id":"d39ba014.14019","type":"debug","z":"58014e9a.6e855","name":"","active":true,"tosidebar":false,"console":false,"tostatus":false,"complete":"payload.message","targetType":"msg","x":400,"y":280,"wires":[]},{"id":"fb89ae81.f2c83","type":"function","z":"58014e9a.6e855","name":"Extract Image","func":"var newmsg = {};\nnewmsg.payload = msg.payload.imagebase64;\nreturn newmsg;","outputs":1,"noerr":0,"x":380,"y":340,"wires":[["b27bd7c3.7317c8"]]},{"id":"b27bd7c3.7317c8","type":"base64","z":"58014e9a.6e855","name":"","action":"","property":"payload","x":540,"y":340,"wires":[["91bb6869.60c218","bad44d5a.892d3"]]},{"id":"bad44d5a.892d3","type":"function","z":"58014e9a.6e855","name":"Formdata","func":"var fileData = msg.payload;\nmsg.headers = {'Content-Type': 'multipart/form-data'};\n\nmsg.payload = {\n    'image' : {\n        'value': fileData,\n        'options': {\n            'filename': 'image.jpg'\n        }\n    }\n};\n\nreturn msg;","outputs":1,"noerr":0,"x":680,"y":340,"wires":[["d8472de6.77f36"]]},{"id":"d8472de6.77f36","type":"http request","z":"58014e9a.6e855","name":"","method":"POST","ret":"obj","paytoqs":false,"url":"http://192.168.22.101:5000/v1/vision/detection","tls":"","persist":false,"proxy":"","authType":"","x":850,"y":340,"wires":[["552c82c7.1ead8c"]]},{"id":"552c82c7.1ead8c","type":"function","z":"58014e9a.6e855","name":"Count Persons","func":"var newMsg = {};\nvar count = 0\n\nfor (var i = 0; i < msg.payload.predictions.length; i++) {\n    //newMsg.payload = msg.payload[i];\n    if (msg.payload.predictions[i].label == \"person\"){\n        counter = counter + 1;\n    }\n    //node.send(newMsg);\n}\nnewMsg.payload = \"No. of persons seen: \" + count; \nreturn newMsg;\n","outputs":1,"noerr":0,"x":1040,"y":340,"wires":[["ee525919.93bf58"]]},{"id":"ee525919.93bf58","type":"debug","z":"58014e9a.6e855","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":1230,"y":340,"wires":[]},{"id":"ccee1e48.2c6ca","type":"mqtt-broker","z":"","name":"nucsrv","broker":"192.168.178.20","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

This is exactly what I needed, thank you so much!