Questions on binaries and workflow

I’m new to n8n and am transitioning my workflows from MAKE to n8n. I’ve been experimenting with it in my lab environment and plan to migrate everything to the n8n cloud shortly. While it’s been exciting, I’ve found it somewhat less intuitive than expected, which is understandable.

I want to express my gratitude to those who have worked diligently on n8n. It’s a truly remarkable tool! Thank you for your time and dedication.

To better understand n8n’s functionality, I have a few questions about binaries. I primarily work with Google’s platform and services, such as Google Sheets, Docs, Calendar, and Gmail.

Currently, I’m testing a simple workflow: whenever a new PDF file is uploaded to a Google Drive folder, I want to download it, attach it to an email, and send it using Gmail.

  1. When I run this workflow, I encounter an error indicating that the binary file was not found. The suggested solution i found on the web is to add a “Read/Write to disk” node before attaching the file to the email. Is this the correct approach, or am I missing something? Why is it necessary to convert the file to a binary format before attaching it to the email?

  2. In a similar workflow, I’m trying to upload a file to a different Google Drive folder and then send the newly uploaded file’s link in an email. I haven’t been able to find a way to accomplish this.

  3. When a file is downloaded and becomes part of the workflow, where does n8n save the temporary file?

Please don’t hesitate to ask if my questions seem basic or uninformed. They are currently the missing pieces in my n8n learning journey.

I am using n8n version 1.57
Database: Default
n8n EXECUTIONS_PROCESS setting (default: own, main): not sure what this is
Running n8n via: Docker
Operating system: Ubuntu Server

Describe the problem/error/question

What is the error message (if any)?

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the 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:

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, the following workflow has examples for both the downloading and uploading of files to Google Drive and should answer your questions:

Thanks, JayF,
i was able to follow the example, however, I am facing a new issue: after I download the file and unzip it, the files are present as binary data (under the binary tab) with the correct name and size, but an IF filter to filter only the pdf is not able to locate the file.

The goal of the workflow is to download the zip file, unzip it, extract the pdf, email it as an attachment using gmail (but it is not working)

The problem is less that the data is lost and more that the conditions do not currently work as you expect them (it currently checks if the string filename ends with .pdf, which is not the case). For that reason, the item gets filtered out and so ends up in “Discarded” instead of “Kept.”

What you need to do is to change the field to “Expression” (like that the parameter value gets set dynamically) and then set it to:

{{ $binary.data.fileName }}

That should solve your problem. You can also get a little bit more fancy and convert the values automatically to lowercase to avoid having multiple conditions (no more check for .PDF and .pdf). That is possible by using the method .toLowerCase():

{{ $binary.data.fileName.toLowerCase() }}

or

{{ $binary.data.fileExtension.toLowerCase() }}

and then just compare with .pdf or pdf.

1 Like

Thanks Jan, but i maybe doing something wrong because it is still not working

This is a good opportunity to learn how to debug. Put a Code node in place of the Filter and do console.log($binary), then look at your developer console output. It will show the structure of the input. $binary.data.fileName should be correct, so it’s likely you haven’t ran your previous node properly

ok, let me do it.

Also, not sure if it helps, but here another image

From that image you can infer that $binary.fileName has the value

If i add his code, it passes the pdf file, but it seems to be an empty file:

// Get the binary object
let binaryData = $binary;

// Initialize an empty object to hold only .pdf files
let filteredData = {};

// Loop through the binary object and filter only PDF files
for (let key in binaryData) {
    if (binaryData[key].fileExtension === 'pdf') {
        filteredData[key] = binaryData[key];  // Add .pdf file to the filteredData object
    }
}

// Log the filtered .pdf data to inspect
console.log(filteredData);

// Replace the binary data with only the filtered .pdf files
return [{ json: {}, binary: filteredData }];

it’s looking for the file in binary.data.
therefore, you must return it in [{binary: {data: BINARY_FILE_HERE}}]

sorry, can you be a little more specific? I am still learning. What is that i need to do?

1 Like

Or if you want to send all pdfs in a single email:

still no output (all files discarded)

If I link the Gmail node after the split node, the workflow is successful (1 email for each file).

It is the filter that is not working. I have tried also with the IF node but i am getting the same results (no output)

never mind, i found the error

thank you for your patience!!!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.