windkh / node-red-contrib-telegrambot

Telegram bot nodes for node-red.
Other
256 stars 116 forks source link

download and rename file or photo #275

Closed itsboo07 closed 1 year ago

itsboo07 commented 1 year ago

Hi iam able to download file(document) or photo but it save as file_(number+) [ example: file_1] 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;
}
windkh commented 1 year ago

I can implement this for you. Should not be a problem to add a third argument fileName.

Right now the return value when downloading finished is the full file path (including the fileName). You should be able to use this full filePath in your flow and trigger a file rename. (See also https://discourse.nodered.org/t/renaming-a-file-in-javascript-node/10995)

windkh commented 1 year ago

please test 14.4.0 added a new property fileName

itsboo07 commented 1 year ago

@windkh thanks for responding, sorry for late response, i did check but now i cant even able to save file locally...before i used the same code to save files.


msg.payload.download = {
    fileId: msg.originalMessage.document.file_id,
    filePath: "/config/tmp/"
    //fileName: "tele.jpg"
};
return msg;
itsboo07 commented 1 year ago

edit: it works i did a mistake in node flow.. how could i save a picture from telegram ? for now im using web link to download file using http request (GET method).

windkh commented 1 year ago

I don't understand your question... you can download a file using msg.payload.download

windkh commented 1 year ago

edit: it works i did a mistake in node flow.. how could i save a picture from telegram ? for now im using web link to download file using http request (GET method).

The same is done internally by the bot when downloading files file_id --> weblink --> GET --> stream --> save