# Filename as timestamp

**URL:** https://discourse.nodered.org/t/filename-as-timestamp/40118
**Category:** General
**Created:** [31 January 2021 16:02 UTC](https://discourse.nodered.org/t/filename-as-timestamp/40118 "2021-01-31T16:02:55Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Baigars](https://avatars.discourse-cdn.com/v4/letter/b/82dd89/32.png) [@Baigars](https://discourse.nodered.org/u/Baigars)
#### Post date: [31 January 2021 16:02 UTC](https://discourse.nodered.org/t/filename-as-timestamp/40118/1 "2021-01-31T16:02:55Z")

</div>

Hi everyone.  
i wanted to make time lapse with esp32 cam, the capture works and to save the picture works but only with predefined filename.  
i have no idea how to change the file name with function, googled everything but nothing helps. maybe the structure of flow is wrong. `[{"id":"f294910.f0d6b7","type":"http request","z":"b09f8b86.982948","name":"","method":"GET","ret":"bin","paytoqs":"ignore","url":"http://192.168.8.185/capture","tls":"","persist":false,"proxy":"","authType":"","x":330,"y":160,"wires":[["61466c09.36c0b4","124ca5a2.d78b6a"]],"outputLabels":["{{payload}}"]},{"id":"f3c9477d.0c36b8","type":"inject","z":"b09f8b86.982948","name":"get image","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"","topic":"","payload":"","payloadType":"date","x":520,"y":20,"wires":[["f294910.f0d6b7"]]},{"id":"ba89cb7c.457638","type":"debug","z":"b09f8b86.982948","name":"","active":true,"console":"false","complete":"payload","x":910,"y":120,"wires":[]},{"id":"5a301d20.a5cfe4","type":"file","z":"b09f8b86.982948","name":"save image","filename":"","appendNewline":false,"createDir":true,"overwriteFile":"true","x":1010,"y":60,"wires":[["3fe2de27.ec8322","d5e2c8f1.cd32a8"]]},{"id":"db28bec7.af775","type":"image","z":"b09f8b86.982948","name":"","width":160,"data":"payload","dataType":"msg","thumbnail":false,"active":true,"pass":false,"outputs":0,"x":720,"y":160,"wires":[]},{"id":"61466c09.36c0b4","type":"image viewer","z":"b09f8b86.982948","name":"","width":160,"data":"payload","dataType":"msg","x":490,"y":180,"wires":[[]]},{"id":"124ca5a2.d78b6a","type":"base64","z":"b09f8b86.982948","name":"","action":"","property":"payload","x":520,"y":120,"wires":[["db28bec7.af775","8b177b28.8fa588","5a301d20.a5cfe4"]]},{"id":"d5e2c8f1.cd32a8","type":"file in","z":"b09f8b86.982948","name":"","filename":"","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":1230,"y":60,"wires":[["2dd9c49a.5a23cc"]]},{"id":"2dd9c49a.5a23cc","type":"image","z":"b09f8b86.982948","name":"","width":160,"data":"payload","dataType":"msg","thumbnail":false,"active":true,"pass":false,"outputs":0,"x":1200,"y":140,"wires":[]},{"id":"3fe2de27.ec8322","type":"image","z":"b09f8b86.982948","name":"","width":160,"data":"payload","dataType":"msg","thumbnail":false,"active":true,"pass":false,"outputs":0,"x":1000,"y":160,"wires":[]},{"id":"8b177b28.8fa588","type":"function","z":"b09f8b86.982948","name":"","func":"var now = new Date();\n// Create formatted time\nvar yyyy = now.getFullYear();\nvar mm = now.getMonth() < 9 ? \"0\" + (now.getMonth() + 1) : (now.getMonth() + 1); // getMonth() is zero-based\nvar dd = now.getDate() < 10 ? \"0\" + now.getDate() : now.getDate();\nvar hh = now.getHours() < 10 ? \"0\" + now.getHours() : now.getHours();\nvar mmm = now.getMinutes() < 10 ? \"0\" + now.getMinutes() : now.getMinutes();\nvar ss = now.getSeconds() < 10 ? \"0\" + now.getSeconds() : now.getSeconds();\n\n// file path with / at the end\nvar path = \"/home/pi/bildessss/\"; // This is the path\nvar filename = \"cam3_\"+yyyy+mm+dd+\"-\"+hh+mm+ss+\".jpg\"; // file name\nreturn msg.filename;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":720,"y":60,"wires":[["5a301d20.a5cfe4","ba89cb7c.457638"]],"outputLabels":["msg.filename"]}]`

---

<div class="post-metadata">

### Author: ![ncherry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ncherry/32/27_2.png) [@ncherry](https://discourse.nodered.org/u/ncherry)
#### Post date: [31 January 2021 17:44 UTC](https://discourse.nodered.org/t/filename-as-timestamp/40118/2 "2021-01-31T17:44:22Z")

</div>

Could you tell me which node image and image-viewer belong to?

From the code above it appears that you base64 is going to save. That save node needs a msg.filename to be sent with the rest of the mesage. I think if you disconnect the direct base64 to save and let the function node add the filename to the msg object you'll solve the issue (I think).

---

<div class="post-metadata">

### Author: ![ncherry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ncherry/32/27_2.png) [@ncherry](https://discourse.nodered.org/u/ncherry)
#### Post date: [31 January 2021 17:59 UTC](https://discourse.nodered.org/t/filename-as-timestamp/40118/3 "2021-01-31T17:59:55Z")

</div>

oops, sorry, not fully awake.

```auto
// file path with / at the end
var path = "/home/pi/bildessss/"; // This is the path
var filename = "cam3_"+yyyy+mm+dd+"-"+hh+mm+ss+".jpg"; // file name
return msg.filename;

```

Change the above (in the function node) to this:

```auto
// file path with / at the end
var path = "/home/pi/bildessss/"; // This is the path
var filename = "cam3_"+yyyy+mm+dd+"-"+hh+mm+ss+".jpg"; // file name
msg.filename = path + filename;
return msg;

```

What this does is to add the filename attribute to the msg.

And remove the wires between the base64 node and the save node.

---

<div class="post-metadata">

### Author: ![Baigars](https://avatars.discourse-cdn.com/v4/letter/b/82dd89/32.png) [@Baigars](https://discourse.nodered.org/u/Baigars)
#### Post date: [31 January 2021 18:16 UTC](https://discourse.nodered.org/t/filename-as-timestamp/40118/4 "2021-01-31T18:16:13Z")

</div>

wow thanks this works perfectly, o ok now i understand how the return works. thank you

---

<div class="post-metadata">

### Author: ![ncherry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ncherry/32/27_2.png) [@ncherry](https://discourse.nodered.org/u/ncherry)
#### Post date: [31 January 2021 18:17 UTC](https://discourse.nodered.org/t/filename-as-timestamp/40118/5 "2021-01-31T18:17:58Z")

</div>

YW, can you post the image nodes (what node-red-contrib-... name). When i looked image up I got at least half a dozen. Sorry I'm curious.

---

<div class="post-metadata">

### Author: ![Baigars](https://avatars.discourse-cdn.com/v4/letter/b/82dd89/32.png) [@Baigars](https://discourse.nodered.org/u/Baigars)
#### Post date: [31 January 2021 18:28 UTC](https://discourse.nodered.org/t/filename-as-timestamp/40118/6 "2021-01-31T18:28:15Z")

</div>

one is node-red-contrib-image-output `https://flows.nodered.org/node/node-red-contrib-image-output` and other is node-red-contrib-image-tools `https://flows.nodered.org/node/node-red-contrib-image-tools` output is only simple debug picture mode but tools it has some cool features like image scaling, invert ,text on top ... and other features like barcode output

---

<div class="post-metadata">

### Author: ![ncherry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ncherry/32/27_2.png) [@ncherry](https://discourse.nodered.org/u/ncherry)
#### Post date: [31 January 2021 18:53 UTC](https://discourse.nodered.org/t/filename-as-timestamp/40118/7 "2021-01-31T18:53:20Z")

</div>

> [@Baigars](#):
>
> [node-red-contrib-image-tools (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-image-tools)

Thanks! I haven't tackled cameras yet. A future project. I'm still trying to work out how to get the images to the TV which my likes to watch in some easy to use manner.

PS yes node-red is a different way of thinking (ex: async programming). 🙂

---

<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: [14 February 2021 18:53 UTC](https://discourse.nodered.org/t/filename-as-timestamp/40118/8 "2021-02-14T18:53:54Z")

</div>

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