But I noticed that this is not an efficient way of doing so. Basically I have modified my flow to dynamically set my filenames based on flow variables like this:
let d = new Date().toISOString().slice(0, 10);
let id = msg.payload.id;
let ref = msg.payload.reference;
let filename = '/home/ubuntu/logs/'+id+'_'+ref+'_'+d+'.csv';
const delimiter = ','
flow.set('excel-log-file', filename)
return {}
This works well but now I am having trouble iterating through the actual files to attach them and can't seem to find a way to do so... Should it maybe be easier to send the whole folder (as in /home/ubuntu/logs) not sure if that is possible.
Please any ideas would be great! Thanks in advance.
Have you thought of setting a single flow variable instead, but an array of strings to the paths, to be unloaded when adding the attachments?
You could also take a look at node-red-contrib-fs with the setting all files in a single message. That gets you a set of files following a pattern inside that logs folder. If you store that array in a flow variable or sending it directly upstream you can use it that way.
@afelixnode-red-contrib-fs looks like exactly what I need! I'll give it a try in the morning. Also haven't thought of the array an unloading great idea! Will see if this works, thanks!
For some reason node-red-contrib-fs did not give me any output? I had a debug node set to msg.payload but nothing on debug console
Not sure why that is but I found another useful package that does the same node-red-contrib-fs-ops which installed a couple of extra other nodes that are useful for local filesystem operations.
The fs-ops-dir node did its thing and returned an array of strings with the file names in the specific directory. I'll now try manipulate this array to create array of paths to feed upstream to email node in attachments.
what pattern/directory had you have node-red-contrib-fs's file-lister look at? Based on your initial post it should be something like /home/ubuntu/logs/*.csv
Would have liked the node-red-contrib-fs file-lister to work since it has the "include full path in output" checkbox which I guess would have returned the full path. Instead I'll have to add a function node to build paths seeing that fs-ops-dir node of node-red-contrib-fs-ops only returns array of files and does not have the option to return full path
I’ll take a look at it later, I noticed this morning I made an error in a Pull Req I placed that got accepted, so I’ll be diving in the code either way.