How to send pictures to a POST API?

Hello everyone,

I have to dialog with an API who will give me a "score" for each picture I send for deep learning vision.

So I'm trying to send pictures to the POST API but as far, i couldn't succeed.

The http request node seems to be well configured as I receive this kind of errors :
"{"detail":[{"loc":["body","file"],"msg":"Expected UploadFile, received: <class str'>","type":"value_error"}]}"

I think that I have a format error in my code but I can't figured out with it.

I also tried to transform my picture to a buffer array but even like that I couldn't succeed.

Please help me !

Here is the flow I made :
(For security reasons, I had to remove URL / TLS / Authentication token and proxy from the http request node)

[{"id":"ebd94d8a.3961b","type":"inject","z":"307bb120.7c02ce","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":900,"wires":[["d291267.73832d8"]]},{"id":"af5063f4.a57ea","type":"file-buffer","z":"307bb120.7c02ce","name":"","mode":"asStream","x":320,"y":980,"wires":[["27edfe17.6e4842","df6e18cef8ae507d"]]},{"id":"d291267.73832d8","type":"function","z":"307bb120.7c02ce","name":"Filename","func":"msg.payload = 'C:\\\\PicturesCobot\\\\Cobot00002.JPG';\nmsg.filename = 'C:\\\\PicturesCobot\\\\Cobot00002.JPG';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":170,"y":980,"wires":[["af5063f4.a57ea"]]},{"id":"27edfe17.6e4842","type":"debug","z":"307bb120.7c02ce","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":470,"y":940,"wires":[]},{"id":"cfc9bd999a61915a","type":"http request","z":"307bb120.7c02ce","name":"","method":"POST","ret":"txt","paytoqs":"query","url":"https://","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":690,"y":980,"wires":[["1912b45bd188dc45"]]},{"id":"1912b45bd188dc45","type":"debug","z":"307bb120.7c02ce","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":830,"y":940,"wires":[]},{"id":"df6e18cef8ae507d","type":"function","z":"307bb120.7c02ce","name":"Body + Headers","func":"var fileStream = msg.payload;//msg.file;//msg.filename;\n\nmsg.payload = {\n        \"file\": fileStream,\n        \"type\":\"image/jpg\",\n        \"submission_id\":\"1305197593\"\n        };\nmsg.headers = {\n    'content-type': 'multipart/form-data'\n};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":500,"y":980,"wires":[["cfc9bd999a61915a","08ae3595ebae19f0"]]},{"id":"08ae3595ebae19f0","type":"debug","z":"307bb120.7c02ce","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":670,"y":940,"wires":[]}]

Regards

what is this API ? is there any documentation on its use online ?

Have you tried also with the Read File node ?

image

.. its part of the core nodes and it also supports reading a file as buffer.

Many thanks to UnborN who be able to help me.

I post the flow below for those who were interested.
(Of course i deleted URL / proxy / TLS / and authentication token for security reasons)

[{"id":"3c4ec14821274df5","type":"debug","z":"307bb120.7c02ce","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":990,"y":380,"wires":[]},{"id":"79acec6029bae02a","type":"function","z":"307bb120.7c02ce","name":"Body + Headers","func":"var fileStream = msg.payload;\nlet filename = msg.filename.split(\"\\\\\")[2];\nlet bearer = ''; //Place token here\n\nmsg.payload = {\n    \"file\": {\n        \"value\": fileStream,\n        \"options\": {\n            \"filename\": filename\n        }\n    },\n    \"submission_id\":\"1305197593\"\n};\nmsg.headers = {\n    'content-type': 'multipart/form-data',\n    'Authorization': bearer\n};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":660,"y":420,"wires":[["a28c2c95a2265ef4","25e6cdba760c0b57"]]},{"id":"a28c2c95a2265ef4","type":"debug","z":"307bb120.7c02ce","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":830,"y":380,"wires":[]},{"id":"834b3c9078bfa91c","type":"inject","z":"307bb120.7c02ce","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":420,"wires":[["a98d80f7ce3def87"]]},{"id":"f2a2011866259697","type":"file-buffer","z":"307bb120.7c02ce","name":"","mode":"asStream","credentials":{},"x":470,"y":420,"wires":[["15eb82fbcce0c208","79acec6029bae02a"]]},{"id":"a98d80f7ce3def87","type":"function","z":"307bb120.7c02ce","name":"Filename","func":"msg.payload = 'C:\\\\PicturesCobot\\\\Cobot00003.JPG';\nmsg.filename = 'C:\\\\PicturesCobot\\\\Cobot00003.JPG';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":420,"wires":[["f2a2011866259697"]]},{"id":"15eb82fbcce0c208","type":"debug","z":"307bb120.7c02ce","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":630,"y":380,"wires":[]},{"id":"25e6cdba760c0b57","type":"http request","z":"307bb120.7c02ce","name":"","method":"POST","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"credentials":{"user":"","password":""},"x":850,"y":420,"wires":[["3c4ec14821274df5"]]}]

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