Describe the problem/error/question
I’m using an Airtable list node to return records and will download attachments if they are present. I have a functioning workflow which send this data to a ‘Move Binary Data’ node and converts the file into a base64 string to be used later. My problem is that if more than 1 file is present, I need to be able to iterate over the binary files and convert each one - right now I am only able to access the first file (stored in ‘attachment_0’.
I have tried to write a JS function to do this and tried many iterations, but not managed to get it to work the way I need:
const items = [];
for (let i = 0; i < $input.item.json.fields.attachments.length; i++) {
const binaryData = $input.item.binary[`attachments_${i}`].data;
const base64Data = Buffer.from(binaryData).toString('base64');
items.push({
json: {
attachment: base64Data
}
});
}
return items;
What is the error message (if any)?
Please share your workflow
Share the output returned by the last node
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: