# NodeRed with Hikvision

**URL:** <https://discourse.nodered.org/t/nodered-with-hikvision/46514>\
**Category:** General\
**Created:** [31 May 2021 15:28 UTC](https://discourse.nodered.org/t/nodered-with-hikvision/46514 "2021-05-31T15:28:42Z")\
**Posts on this page:** 8\
**Page:** 2

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [6 June 2021 13:04 UTC](https://discourse.nodered.org/t/nodered-with-hikvision/46514/22 "2021-06-06T13:04:23Z")

</div>

Steve just beat me to it.

I was going to say... try this out - I've put a 'jpg' on my server for you to try.

```auto
msg.payload = { chatId: "xxxxxxxxxxxx", 
                type:"photo", 
                content:"http://resources-area.co.uk/pics_of_places/san_francisco.jpg",
                caption:"Picture from the front camera"};

return msg;

```

---

<div class="post-metadata">

**Author:** ![automati](https://avatars.discourse-cdn.com/v4/letter/a/b2d939/32.png) [@automati](https://discourse.nodered.org/u/automati)\
**Post date:** [6 June 2021 13:12 UTC](https://discourse.nodered.org/t/nodered-with-hikvision/46514/23 "2021-06-06T13:12:24Z")

</div>

Is there still a way to save the picture first? because I want to take a picture when there is movement, but only send it if the door contact opens later ... for that I would have to save the picture first and then retrieve it?

---

<div class="post-metadata">

**Author:** ![automati](https://avatars.discourse-cdn.com/v4/letter/a/b2d939/32.png) [@automati](https://discourse.nodered.org/u/automati)\
**Post date:** [6 June 2021 13:15 UTC](https://discourse.nodered.org/t/nodered-with-hikvision/46514/24 "2021-06-06T13:15:42Z")

</div>

It worked! So I have the wrong file path with me?

---

<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 June 2021 13:16 UTC](https://discourse.nodered.org/t/nodered-with-hikvision/46514/25 "2021-06-06T13:16:35Z")

</div>

You can store the picture in flow/global context or you can write the buffer to a file for later retrieval.

e.g..

split that function into 2 parts and put a change node or file node in between them

function 1 --\> change node --\> function 2 --\> telegram

#### function 1 - convert image to buffer

```javascript
var imgBase64 = msg.payload;
var pos = imgBase64.indexOf("base64,");
imgBase64 = imgBase64.substr(pos + 7);
var imgData = Buffer.from(imgBase64, "base64");
msg.payload = imgData;
return msg;

```

#### change node

`set flow.image to msg.payload`

#### function 2 - build the telegram msg

```javascript
msg.payload = {
  content: msg.payload,
  caption: `Image from camera`,
  type: 'photo',
  chatId: xxxxx // << update this
}
msg.payload.options = { parse_mode: "Markdown" };
return msg;

```

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [6 June 2021 13:27 UTC](https://discourse.nodered.org/t/nodered-with-hikvision/46514/26 "2021-06-06T13:27:04Z")

</div>

> [@automati](#):
>
> It worked! So I have the wrong file path with me?

Depends where the image is located.  
In my last posting the image is on a server.

If it was located in your Pi then you could use (for example)...

`content: "/home/pi/myImages/filename.jpg",`

As Steve said... there are many ways to 'store' your image.

On my home security system I have four RPi-Zero-Ws each fitted with a Pi camera and an infrared detector. Whenever infrared is detected the RPi-Zero-W sends the captured image to an FTP server running on my main RPi-4B which then sends the image via Telegram to my mobile phone.

---

<div class="post-metadata">

**Author:** ![automati](https://avatars.discourse-cdn.com/v4/letter/a/b2d939/32.png) [@automati](https://discourse.nodered.org/u/automati)\
**Post date:** [6 June 2021 13:33 UTC](https://discourse.nodered.org/t/nodered-with-hikvision/46514/27 "2021-06-06T13:33:31Z")

</div>

What should this change node look like?

---

<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 June 2021 13:34 UTC](https://discourse.nodered.org/t/nodered-with-hikvision/46514/28 "2021-06-06T13:34:25Z")

</div>

> [@Steve-Mcl](#):
>
> set flow.image to msg.payload

⬆ like that.

---

<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 June 2021 13:35 UTC](https://discourse.nodered.org/t/nodered-with-hikvision/46514/29 "2021-06-20T13:35:08Z")

</div>

Closed on 20 June 2021 13:35 UTC

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

[Previous page](https://discourse.nodered.org/t/nodered-with-hikvision/46514.md?page=1)
