Download and rename file

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

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

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.

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 .

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

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

@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?

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

[{"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":[]}]

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

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