Fetch image and send to email

I'm trying to fetch a camera shot via the Fully Kiosk Browser REST API and send it via email. I can get it to send the email, but the attachment doesn't come through as a valid image. If I call the endpoint directly from my browser it pulls up an image, and if I send it to a debug node I see the binary buffer.

I found this change node elsewhere in the forums, but it's not working for me. Anyone have any ideas?

[{"id":"84b6a7e.5bf7958","type":"change","z":"534682e6.98503c","name":"Setup mail content","rules":[{"t":"set","p":"cid","pt":"msg","to":"","tot":"date"},{"t":"set","p":"attachments","pt":"msg","to":"[{\t \"filename\": 'cam_' & $replace($now(),\":\",\"_\") & '.jpg', \t \"content\": $$.payload,\t \"cid\": \"\" & cid & \"\"\t}]","tot":"jsonata"},{"t":"set","p":"topic","pt":"msg","to":"Dashboard Camera","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"'<img src=\"cid:' & cid & '\"/>'","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":760,"wires":[["e6f619ff.be4a58","bc454c64.2a513"]]}]

So the main part of that change node is where it sets up the attachment...

JSONata...

[{
 "filename": 'cam_' & $replace($now(),":","_") & '.jpg', 
 "content": $$.payload,
 "cid": "" & cid & ""
}]

Does the msg going into this change node have a property msg.cid and is the image buffer in msg.payload?

The msg.cid is set up in the first part of that change node to a timestamp. I've also tried just flowing the binary buffer to the email node as the msg.payload, which it says (and does) send as an attachment, but it doesn't come through as a valid image.

Here's my HTTP request node that goes into that change node:

[{"id":"9baad2b5.91bf8","type":"http request","z":"534682e6.98503c","name":"","method":"GET","ret":"bin","paytoqs":"ignore","url":"http://192.168.1.76:2323?cmd= getCamshot&password={{fkb_pwd}}","tls":"","persist":false,"proxy":"","authType":"","x":280,"y":800,"wires":[["84b6a7e.5bf7958"]]}]

AFAICT that seems to be working. It's getting the fkb_pwd value from a credentials node I put in front of it and it's successfully returning from the call. The REST interface is described here:

https://www.fully-kiosk.com/en/#rest

The call when I make it via the browser is returning an image.

I cant see the FULL msg (that goes into the change node) so I cant verify the required values are set (or valid)

Can you screenshot the FULL msg (set debug node to output complete message) that goes into the change node and screenshot the payload coming out of the change node. (expand all properties before screenshots);

also, capture the first 10 bytes of the image buffer (by expanding msg.attachements[0].content )

Here it is going into and out of that change node (edited to remove pwd)

The buffer is not an image...

image

It is HTML. Probably a log in screen.

Are you using the correct URL for this camera?

What type of camera is this?

Argh! I had an extra space in the URL between the ? and getCamshot

Now it works! Thanks very much!

No bother.

For future reference (or future readers) click the RAW button next to the buffer in the debug output - you would see this was a HTML string.

1 Like

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