Hello, I have a Read email cron task that runs every 2 minutes and reads and adds all the emails to our database and each attachment. Everything working perfect.
My only issue right now is with the .eml files (but not sure) if this could be an issue with other files.
Simply, my download attachment action is indeed downloading the “binary” file but not usable, it’s just empty for the next nodes:
It looks like the eml file has no filename which makes sense as sometimes they don’t, What you could do is filter them out similar to what you are doing and maybe set a filename for it using a set node assuming it is always going to be attachment_0
Althought the s3 node has a filename field so you could maybe try setting one in there to see if that works.
However, I made this script to give it a name if it doesn’t have one, but doesn’t seem to make any difference:
let results = [];
let index = 0; // index
function generateUniqueString() {
return `unnamed_${Date.now()}_${index}_${Math.random().toString(36).substr(2, 9)}`;
}
for (item of items) {
for (key of Object.keys(item.binary)) {
let baseName, extension;
// If fileName exists
if (item.binary[key].fileName) {
console.log(item.binary[key].fileName);
// Extract the filename and extension
let parts = item.binary[key].fileName.split('.');
baseName = parts.slice(0, -1).join('.');
extension = parts[parts.length - 1];
} else {
// Generate a unique base name and get the extension from fileExtension
baseName = generateUniqueString();
extension = item.binary[key].fileExtension || 'bin'; // Using 'bin' as a fallback in case fileExtension is also missing
}
let uniqueFileName = `${baseName}.${extension}`; // No need to append index here since we're generating a unique base name
console.log(uniqueFileName);
results.push({
json: {
fileName: uniqueFileName
},
binary: {
data: item.binary[key],
}
});
index++; // Increment the index for the next filename
}
}
return results;
Nothing because uploading to S3 requires a filename, which in this case I can’t access to.
I guess you mean trying to upload the file directly with a static name, I think that won’t work for my usecase as I “download” all the attachments and run the above script to put them a name if they don’t have one, and I use each binary.fileName to upload them to S3.
I don’t understand why in the first place the name isn’t there when It should, as the file has a name, you can see that in the gmail inbox screenshot, but my script should add a name, but it’s still not working…
I am not sure on that either, I will need to create an eml file to test with properly. Looking at the output of your code node it isn’t adding a name which is also strange. I will set aside some time on Monday morning to test this.
Hi @Jon did you have a chance to test this out? Not urgent, just following up. I don’t get .eml files very often, but I would like to get a workaround for this.