# Fetch image and send to email

**URL:** <https://discourse.nodered.org/t/fetch-image-and-send-to-email/43738>\
**Category:** General\
**Created:** [6 April 2021 03:31 UTC](https://discourse.nodered.org/t/fetch-image-and-send-to-email/43738 "2021-04-06T03:31:33Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcarreira](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jcarreira/32/39830_2.png) [@jcarreira](https://discourse.nodered.org/u/jcarreira)\
**Post date:** [6 April 2021 03:31 UTC](https://discourse.nodered.org/t/fetch-image-and-send-to-email/43738/1 "2021-04-06T03:31:33Z")

</div>

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"]]}]`

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [6 April 2021 07:00 UTC](https://discourse.nodered.org/t/fetch-image-and-send-to-email/43738/2 "2021-04-06T07:00:23Z")

</div>

> [@jcarreira](#):
>
> I found this change node elsewhere in the forums, but it's not working for me

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

JSONata...

```auto
[{
 "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`?

---

<div class="post-metadata">

**Author:** ![jcarreira](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jcarreira/32/39830_2.png) [@jcarreira](https://discourse.nodered.org/u/jcarreira)\
**Post date:** [6 April 2021 10:38 UTC](https://discourse.nodered.org/t/fetch-image-and-send-to-email/43738/3 "2021-04-06T10:38:05Z")

</div>

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](https://www.fully-kiosk.com/en/#rest)

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

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [6 April 2021 10:52 UTC](https://discourse.nodered.org/t/fetch-image-and-send-to-email/43738/4 "2021-04-06T10:52:28Z")

</div>

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` )

---

<div class="post-metadata">

**Author:** ![jcarreira](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jcarreira/32/39830_2.png) [@jcarreira](https://discourse.nodered.org/u/jcarreira)\
**Post date:** [6 April 2021 11:02 UTC](https://discourse.nodered.org/t/fetch-image-and-send-to-email/43738/6 "2021-04-06T11:02:18Z")

</div>

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

 ![Screen Shot 2021-04-06 at 7.00.43 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/2/42a0a4075f3b8875b00a86016ae5021ec944ac8e.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [6 April 2021 11:04 UTC](https://discourse.nodered.org/t/fetch-image-and-send-to-email/43738/7 "2021-04-06T11:04:33Z")

</div>

The buffer is not an image...

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/d/1d9d7e546bd56cdb16ffef761f386a56534f57e0.png)

It is HTML. Probably a log in screen.

Are you using the correct URL for this camera?

What type of camera is this?

---

<div class="post-metadata">

**Author:** ![jcarreira](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jcarreira/32/39830_2.png) [@jcarreira](https://discourse.nodered.org/u/jcarreira)\
**Post date:** [6 April 2021 11:08 UTC](https://discourse.nodered.org/t/fetch-image-and-send-to-email/43738/8 "2021-04-06T11:08:44Z")

</div>

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

Now it works! Thanks very much!

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [6 April 2021 11:11 UTC](https://discourse.nodered.org/t/fetch-image-and-send-to-email/43738/9 "2021-04-06T11:11:54Z")

</div>

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.

---

<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:** [20 April 2021 11:12 UTC](https://discourse.nodered.org/t/fetch-image-and-send-to-email/43738/10 "2021-04-20T11:12:09Z")

</div>

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