# Please help me format my HTTP POST so that the data of the image actually gets sent

**URL:** <https://discourse.nodered.org/t/please-help-me-format-my-http-post-so-that-the-data-of-the-image-actually-gets-sent/90197>\
**Category:** General\
**Tags:** dashboard-2\
**Created:** [15 August 2024 14:36 UTC](https://discourse.nodered.org/t/please-help-me-format-my-http-post-so-that-the-data-of-the-image-actually-gets-sent/90197 "2024-08-15T14:36:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![no\_mpimpi](https://avatars.discourse-cdn.com/v4/letter/n/f14d63/32.png) [@no\_mpimpi](https://discourse.nodered.org/u/no_mpimpi)\
**Post date:** [15 August 2024 14:36 UTC](https://discourse.nodered.org/t/please-help-me-format-my-http-post-so-that-the-data-of-the-image-actually-gets-sent/90197/1 "2024-08-15T14:36:09Z")

</div>

Hi all,

I desperately need help formatting a POST command. I've searched, but obviously not well, or I'd not be posting. I've lost a day to this, and I'm beating my head against the wall.

I'm trying to send an image to a Codeproject.ai-server, so it'll tell me what's in the pic. To connect with the server, I am using the HTTP POST command as described in the [Codeproject API](https://www.codeproject.com/AI/docs/api/api_reference.html#example_6).

I get a jpg from a camera node; it does arrive, I can see it on my dashboard2. I wrap it in the required headers using a function node. Then I POST it.

The flow below does actually work, but the error that I'm receiving makes it clear that no image data arrived. As far as I can figure, therefore, I am somehow screwing up the formatting of the POST command. It has to be.

This is my flow:

```auto

[{"id":"eeaca59f759000ea","type":"inject","z":"8f99f3189f7e4f1d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":370,"y":240,"wires":[["442e2916c631ddc9"]]},{"id":"652ee96c8ed4c785","type":"ui-template","z":"8f99f3189f7e4f1d","group":"47ac84fa59116547","page":"","ui":"","name":"","order":2,"width":0,"height":0,"head":"","format":"<img :src=\"msg.payload\">","storeOutMessages":true,"passthru":true,"resendOnRefresh":true,"templateScope":"local","className":"","x":780,"y":320,"wires":[[]]},{"id":"2f16ff9a923d4752","type":"debug","z":"8f99f3189f7e4f1d","name":"yAyI!","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1070,"y":240,"wires":[]},{"id":"b37f4dafdf04e74e","type":"function","z":"8f99f3189f7e4f1d","name":"function 26","func":"const thisimage = msg.payload;\n\nmsg = {\n headers: {\n 'content-type': 'multipart/form-data',\n },\n payload: {\n 'image': {\n 'value': thisimage,\n 'options': {\n 'filename': 'snapshot.jpg'\n }\n },\n 'min_confidence': 0.0\n }\n};\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":730,"y":240,"wires":[["3caba20b723cc336"]]},{"id":"3caba20b723cc336","type":"http request","z":"8f99f3189f7e4f1d","name":"","method":"POST","ret":"obj","paytoqs":"body","url":"http://server:32168/v1/vision/custom/ipcam-general","tls":"","persist":true,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":910,"y":240,"wires":[["2f16ff9a923d4752"]]},{"id":"442e2916c631ddc9","type":"hikvisionUltimatePicture","z":"8f99f3189f7e4f1d","name":"Room","topic":"","server":"bd732490a1f706cc","channelID":"8","rotateimage":"0","heightimage":"480","widthimage":"576","qualityimage":"100","cropimage":"","textoverlay":"","textoverlayXY":"0,0","textoverlayWH":"0,0","textoverlayFont":"FONT_SANS_32_WHITE","urlImageCurrentIndex":0,"x":510,"y":240,"wires":[["b37f4dafdf04e74e","652ee96c8ed4c785"],[]]},{"id":"47ac84fa59116547","type":"ui-group","name":"Image","page":"f59a4ca419fb842f","width":"6","height":"1","order":-1,"showTitle":true,"className":"","visible":"true","disabled":"false"},{"id":"bd732490a1f706cc","type":"Hikvision-config","host":"0.0.0.0","port":"80","name":"Server","authentication":"digest","protocol":"http","heartbeattimerdisconnectionlimit":"2","deviceinfo":"[object Object]","debuglevel":"no"},{"id":"f59a4ca419fb842f","type":"ui-page","name":"Motion tests","ui":"cf9dc2ba60d1396c","path":"/page3","icon":"home","layout":"grid","theme":"7ba40ffa60b22682","order":3,"className":"","visible":true,"disabled":"false"},{"id":"cf9dc2ba60d1396c","type":"ui-base","name":"My Dashboard","path":"/dashboard","includeClientData":true,"acceptsClientConfig":["ui-notification","ui-control"],"showPathInSidebar":true,"showPageTitle":true,"navigationStyle":"default","titleBarStyle":"default"},{"id":"7ba40ffa60b22682","type":"ui-theme","name":"Default Theme","colors":{"surface":"#ffffff","primary":"#0080ff","bgPage":"#eeeeee","groupBg":"#ffffff","groupOutline":"#cccccc"},"sizes":{"pagePadding":"12px","groupGap":"12px","groupBorderRadius":"4px","widgetGap":"12px"}}]

```

This is an example of the error:  
`

`{"headers":{"content-length":"328","content-type":"application/json","date":"Thu, 15 Aug 2024 14:28:49 GMT","server":"Kestrel","x-node-red-request-node":"07589556"},"payload":{"error":"Yolo returned null.","inferenceMs":0,"processMs":0,"analysisRoundTripMs":3,"success":false,"moduleName":"Object Detection (YOLOv5 .NET)","moduleId":"ObjectDetectionYOLOv5Net","command":"custom","requestId":"99ae0ae1-47c7-4c09-8240-723354a1c6d4","processedBy":"localhost","timestampUTC":"Thu, 15 Aug 2024 14:28:49 GMT"},"_msgid":"107d1105103317fe","statusCode":200,"responseUrl":"http://server:32168/v1/vision/custom/ipcam-general","redirectList":[],"retry":0}`

Please, for the love of whatever entity you please, help. I am a broken human being.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [15 August 2024 15:07 UTC](https://discourse.nodered.org/t/please-help-me-format-my-http-post-so-that-the-data-of-the-image-actually-gets-sent/90197/2 "2024-08-15T15:07:00Z")

</div>

The HIK image node outputs a base64encoded image in msg.payload.  
The binary encoded image is in msg.forEmail.  
Try sending the binary data.

---

<div class="post-metadata">

**Author:** ![no\_mpimpi](https://avatars.discourse-cdn.com/v4/letter/n/f14d63/32.png) [@no\_mpimpi](https://discourse.nodered.org/u/no_mpimpi)\
**Post date:** [15 August 2024 15:33 UTC](https://discourse.nodered.org/t/please-help-me-format-my-http-post-so-that-the-data-of-the-image-actually-gets-sent/90197/3 "2024-08-15T15:33:30Z")

</div>

You're a beautiful person, thank you so much!

For any other person who stumbles here via search, here is the final function:

```auto
const thisimage = msg.forEmail;
msg = {
    headers: {
        'content-type': 'multipart/form-data',
    },
    payload: {
        'image': {
            'value': thisimage,
            'options': {
                'filename': 'snapshot.jpg'
            }
        },
        'min_confidence': 0.0
    }
};
return msg;

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [15 August 2024 15:38 UTC](https://discourse.nodered.org/t/please-help-me-format-my-http-post-so-that-the-data-of-the-image-actually-gets-sent/90197/4 "2024-08-15T15:38:23Z")

</div>

Can't help with the head contusions, but at least you are there now.

It was nice to see a well presented issue with all the data required to help you.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [29 August 2024 15:38 UTC](https://discourse.nodered.org/t/please-help-me-format-my-http-post-so-that-the-data-of-the-image-actually-gets-sent/90197/5 "2024-08-29T15:38:43Z")

</div>

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