Course/Chapter 5/5. Binary Data & File Handling
    intermediate
    Chapter 5: Data Transformation & Manipulation

    5. Binary Data & File Handling

    Process files, images, and attachments.

    20m Lesson 5 of 5

    n8n handles binary data (files, images, PDFs) alongside JSON data. Learn to download, process, convert, and upload files within your workflows.

    Common File Operations

    • - Download files from URLs
    • - Read CSV/Excel files into JSON
    • - Generate PDFs from templates
    • - Resize and optimize images
    • - Upload files to S3, Google Drive, or FTP

    Code Examples

    Convert CSV to JSON Items
    javascript
    // After downloading a CSV with HTTP Request node:
    // Use the "Spreadsheet File" node with:
    // - Operation: Read From File
    // - File Format: CSV
    // - Header Row: true
    
    // Or in Code node:
    const csv = $input.first().binary.data;
    const text = Buffer.from(csv.data, "base64").toString();
    const lines = text.split("\n");
    const headers = lines[0].split(",");
    
    return lines.slice(1).filter(l => l.trim()).map(line => {
      const values = line.split(",");
      const obj = {};
      headers.forEach((h, i) => obj[h.trim()] = values[i]?.trim());
      return { json: obj };
    });

    Pro Tips

    • 💡Use the "Move Binary Data" node to convert between JSON and binary formats

    Comprehension Quiz

    Answer 2 of 2 correctly to unlock lesson completion.

    1. What is binary data in n8n?

    2. Which node converts between JSON and binary formats?

    Pass the quiz above to unlock lesson completion