Where is my issue Http request push jpg

I am currently using Node-red in HA. I am attempting to push a JPG to Codeproject AI local server to get an OCR response back. I am getting responses back from the server, but I don't think it's getting the jpg data. As it always errors out in 6ms or less. My code is below. I can't figure out how to past it correctly. There is no </> button. Where am I going wrong?

[{"id":"fdf45dde0884a088","type":"inject","z":"4f64858a3d766e69","name":"","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":110,"y":600,"wires":[["6ab53aa60a5a28ac"]]},{"id":"25bd7939565752ad","type":"debug","z":"4f64858a3d766e69","name":"debug 15","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":640,"y":480,"wires":[]},{"id":"0a5e31bf976b3eac","type":"http request","z":"4f64858a3d766e69","name":"","method":"POST","ret":"obj","paytoqs":"body","url":"http://10.146.1.30:32168/v1/image/ocr","tls":"","persist":true,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"Content-Type","keyValue":"","valueType":"image/jpeg","valueValue":""}],"x":490,"y":480,"wires":[["25bd7939565752ad"]]},{"id":"6ab53aa60a5a28ac","type":"file in","z":"4f64858a3d766e69","name":"","filename":"/config/save_data/test1.jpg","filenameType":"str","format":"","chunk":false,"sendError":false,"encoding":"hex","allProps":false,"x":240,"y":480,"wires":[["0a5e31bf976b3eac"]]}]

The code below is from the Codepoject AI web site and works if i load it on a web browser.

<html>
<body>
Detect the scene in this file: <input id="image" type="file" />
<input type="button" value="Detect Scene" onclick="detectScene(image)" />

<script>
function detectScene(fileChooser) {
    var formData = new FormData();
    formData.append('image', fileChooser.files[0]);

    fetch('http://localhost:32168/v1/image/ocr', {
        method: "POST",
        body: formData
    })
    .then(response => {
        if (response.ok) response.json().then(data => {
            console.log(`Scene is ${data.label}, ${data.confidence} confidence`)
        });
    });
}
</script>
</body>
</html>

Hi @chrissica06 - welcome to the forums.

The html you have supplied, is a mulit-part form.
Your flow is just sending a blob of data - not a multi-part form

Try the below, I have:

  • Set the content type to multipart/form-data
  • Constructed a a payload with the "form data"
[{"id":"fdf45dde0884a088","type":"inject","z":"c422701e0fbc1756","name":"","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":280,"y":165,"wires":[["6ab53aa60a5a28ac"]]},{"id":"0a5e31bf976b3eac","type":"http request","z":"c422701e0fbc1756","name":"","method":"POST","ret":"obj","paytoqs":"body","url":"http://10.146.1.30:32168/v1/image/ocr","tls":"","persist":true,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"other","keyValue":"Content-Type","valueType":"other","valueValue":"multipart/form-data"}],"credentials":{},"x":920,"y":270,"wires":[[]]},{"id":"6ab53aa60a5a28ac","type":"file in","z":"c422701e0fbc1756","name":"","filename":"/config/save_data/test1.jpg","filenameType":"str","format":"","chunk":false,"sendError":false,"encoding":"hex","allProps":false,"x":405,"y":270,"wires":[["d77729fba8b0d15a"]]},{"id":"d77729fba8b0d15a","type":"function","z":"c422701e0fbc1756","name":"Format Form Data","func":"return {\n    payload: {\n        image: {\n            value: msg.payload,\n            options: {\n                filename: 'test1.jpg'\n            }\n        }\n    }\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":690,"y":270,"wires":[["0a5e31bf976b3eac"]]}]

WOW!!! Thank you! I am still learning and that worked the first time out.

1 Like

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