Hi all,
PLEASE HELP ME! I am trying to download a file from a gmail node but I do not know what is the correct file to download.
In the image below you will see that I have 4 files, could be more or less. But I just want to get the files xlxs.
How can I do it?
Information on your n8n setup
n8n version:
Database (default: SQLite):
n8n EXECUTIONS_PROCESS setting (default: own, main):
Running n8n via (Docker, npm, n8n cloud, desktop app):
Operating system:
n8n
January 27, 2025, 5:39pm
2
It looks like your topic is missing some important information. Could you provide the following if applicable.
n8n version:
Database (default: SQLite):
n8n EXECUTIONS_PROCESS setting (default: own, main):
Running n8n via (Docker, npm, n8n cloud, desktop app):
Operating system:
hi,
try this in a code-Node to only extract the attachment from your email which matches the file-extension “.xls”
// Access the input data
const items = $input.all();
return items.flatMap(item => {
// Ensure there is binary data
if (!item.binary) {
return [];
}
// Filter binary data to keep only .xls files
return Object.keys(item.binary)
.filter(key => item.binary[key].fileExtension === 'xls')
.map(key => {
// Create a new item from attachment
const attachment = item.binary[key];
return {
json: {
fileName: attachment.fileName,
mimeType: attachment.mimeType,
fileSize: attachment.fileSize,
},
binary: {
data: attachment // Keep the attachment binary
}
};
});
});
nabossha:
// Access the input data
const items = $input.all();
return items.flatMap(item => {
// Ensure there is binary data
if (!item.binary) {
return [];
}
// Filter binary data to keep only .xls files
return Object.keys(item.binary)
.filter(key => item.binary[key].fileExtension === 'xls')
.map(key => {
// Create a new item from attachment
const attachment = item.binary[key];
return {
json: {
fileName: attachment.fileName,
mimeType: attachment.mimeType,
fileSize: attachment.fileSize,
},
binary: {
data: attachment // Keep the attachment binary
}
};
});
});
Hi, Thanks but it did not work, I did try somethign similiar but is not working
yes, because you filter for .xls
and in your screenshot / example the file-ending is .xlsx
maybe you wanna consider using mime-type for filtering or check both variants of fileEnding to be sure. depends on how much of control you have over the incoming data.
nabossha:
// Access the input data
const items = $input.all();
return items.flatMap(item => {
// Ensure there is binary data
if (!item.binary) {
return [];
}
// Filter binary data to keep only .xls files
return Object.keys(item.binary)
.filter(key => item.binary[key].fileExtension === 'xls')
.map(key => {
// Create a new item from attachment
const attachment = item.binary[key];
return {
json: {
fileName: attachment.fileName,
mimeType: attachment.mimeType,
fileSize: attachment.fileSize,
},
binary: {
data: attachment // Keep the attachment binary
}
};
});
});
It seems is working. I add and If condition to tun twice to check for .xlsx or .xls.
It has been really usefull.
1 Like
system
Closed
February 3, 2025, 11:24pm
7
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.