# Download and rename file

**URL:** <https://discourse.nodered.org/t/download-and-rename-file/68724>\
**Category:** General\
**Created:** [8 October 2022 15:07 UTC](https://discourse.nodered.org/t/download-and-rename-file/68724 "2022-10-08T15:07:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![boo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/boo/32/67804_2.png) [@boo](https://discourse.nodered.org/u/boo)\
**Post date:** [8 October 2022 15:07 UTC](https://discourse.nodered.org/t/download-and-rename-file/68724/1 "2022-10-08T15:07:47Z")

</div>

Hi iam able to download file(document) or photo from telegram but it saves as `file_(number+)`[example : `file_5`] is their any way to rename or save the file or photo with the name we want.. i want to keep replacing on the existing file soo having same filename could be useful  
code i use to download documents

```auto
if (msg.payload.type === 'document'){
    msg.payload.download = {
        fileId: msg.originalMessage.document.file_id,
        filePath: "/config/tmp/)"
    }
    return msg;
}

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [8 October 2022 16:29 UTC](https://discourse.nodered.org/t/download-and-rename-file/68724/2 "2022-10-08T16:29:49Z")

</div>

How are you saving it?  
What version of Node-RED are you using?  
What node (full name please - i.e. node-red-contrib-??????) are you using?  
Put a `debug` node - set ti display the complete msg object - on the output of the telegram node and expand it all and copy and paste it's information.  
and export and pastine your flow would be helpful too.

---

<div class="post-metadata">

**Author:** ![boo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/boo/32/67804_2.png) [@boo](https://discourse.nodered.org/u/boo)\
**Post date:** [8 October 2022 18:25 UTC](https://discourse.nodered.org/t/download-and-rename-file/68724/3 "2022-10-08T18:25:38Z")

</div>

> [@zenofmud](#):
>
> node-red-contrib

Im using `node-red-contrib-telegrambot` to receive files to nodered from telegram  
Im using nodered inside homeassistant as addon  
NR verison: 13.4.0  
im able to download and save file locally but it saves with name `file_1` or `file_2`  
Instead i want to save file with my own name .

```auto
if (msg.payload.type === 'document'){
    msg.payload.download = {
        fileId: msg.originalMessage.document.file_id,
        filePath: "/config/tmp/)"
    }
    return msg;
}

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [8 October 2022 19:08 UTC](https://discourse.nodered.org/t/download-and-rename-file/68724/4 "2022-10-08T19:08:12Z")

</div>

Not being a home assistant user, you might be better served asking on a homeassistant forum

---

<div class="post-metadata">

**Author:** ![boo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/boo/32/67804_2.png) [@boo](https://discourse.nodered.org/u/boo)\
**Post date:** [8 October 2022 22:38 UTC](https://discourse.nodered.org/t/download-and-rename-file/68724/5 "2022-10-08T22:38:12Z")

</div>

@zenofmud no issue thanks for responding.. one small doubt:  
how do i join two numbers together  
say i want to join `77` and `99` together and look like `7799`?  
they both are numbers ...should i first change them to sting to get this work?

---

<div class="post-metadata">

**Author:** ![smanjunath211](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smanjunath211/32/95742_2.png) [@smanjunath211](https://discourse.nodered.org/u/smanjunath211)\
**Post date:** [9 October 2022 02:56 UTC](https://discourse.nodered.org/t/download-and-rename-file/68724/6 "2022-10-09T02:56:06Z")

</div>

there may be more than one way to do it. I would do as below.

```auto
[{"id":"565838c7796500b7","type":"inject","z":"a1ac2470d38f86ae","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":320,"wires":[["63d4fc10d17300af"]]},{"id":"63d4fc10d17300af","type":"change","z":"a1ac2470d38f86ae","name":"","rules":[{"t":"set","p":"payload1","pt":"msg","to":"77","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":320,"wires":[["9287144ac76e7e86"]]},{"id":"9287144ac76e7e86","type":"change","z":"a1ac2470d38f86ae","name":"","rules":[{"t":"set","p":"payload2","pt":"msg","to":"99","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":320,"wires":[["a16fc10379116f22"]]},{"id":"a16fc10379116f22","type":"change","z":"a1ac2470d38f86ae","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload1&payload2","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":780,"y":320,"wires":[["c9e2039bd6797d4f"]]},{"id":"c9e2039bd6797d4f","type":"debug","z":"a1ac2470d38f86ae","name":"debug 55","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":960,"y":320,"wires":[]},{"id":"d2a0ef194a20a6ea","type":"inject","z":"a1ac2470d38f86ae","name":"","props":[{"p":"payload2","v":"99","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"two","x":250,"y":200,"wires":[["91519fde8037d4f7"]]},{"id":"92cba9bc15051242","type":"inject","z":"a1ac2470d38f86ae","name":"","props":[{"p":"payload1","v":"77","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"one","x":250,"y":120,"wires":[["91519fde8037d4f7"]]},{"id":"91519fde8037d4f7","type":"join","z":"a1ac2470d38f86ae","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":450,"y":140,"wires":[["8f98676c9c460e19"]]},{"id":"8f98676c9c460e19","type":"change","z":"a1ac2470d38f86ae","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload1&payload2","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":140,"wires":[["6842ace0db2ede15"]]},{"id":"6842ace0db2ede15","type":"debug","z":"a1ac2470d38f86ae","name":"debug 54","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":820,"y":140,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![gleba](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gleba/32/50938_2.png) [@gleba](https://discourse.nodered.org/u/gleba)\
**Post date:** [17 October 2022 12:40 UTC](https://discourse.nodered.org/t/download-and-rename-file/68724/7 "2022-10-17T12:40:53Z")

</div>

if you use the web request you can do it directly, if you use the function block you have to rename the file after downloading it

---

<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:** [31 October 2022 12:41 UTC](https://discourse.nodered.org/t/download-and-rename-file/68724/8 "2022-10-31T12:41:36Z")

</div>

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