How to encode binary image data to base64 format in n8n for Odoo integration

Need help with base64 encoding in n8n workflow

I’m working on a workflow where I download images from an API and need to send them to Odoo as base64 encoded data. I’ve been stuck on this for hours and can’t get it working properly.

Here’s my current approach for handling the binary data conversion:

// Extract binary content from previous workflow step
const imageData = $input.first().binary?.file;

if (!imageData) {
  throw new Error("Binary content not available");
}

// Convert binary to base64 format
const encodedImage = imageData.data;

// Generate current timestamp
const currentDate = new Date().toISOString().substring(0, 10);

// Prepare output for next node
return {
  json: {
    attachment_field: encodedImage,
    date_field: currentDate,
    comment_field: $json.comment_field || "",
  },
  binary: {
    file: imageData
  }
};

The binary data I’m working with has these properties:

  • Filename: abc123def456ghi789
  • Path: apifiles/2025/1/987654
  • Extension: jpg
  • Content Type: image/jpeg
  • Size: 42.1 kB

What’s the correct way to handle this conversion? The image data seems to be there but I’m not getting the right base64 output for Odoo.

you’re almost there but missing the buffer conversion step. try Buffer.from(imageData.data, 'base64').toString('base64') or just access imageData.data directly since n8n usually stores it as base64 already. double check what format you’re getting from the previous node first though.

I hit the same issue with Odoo integration - it’s usually a data format problem. N8n’s binary data is already base64 encoded, but hidden characters or encoding issues can mess things up downstream. I added a validation step to clean the base64 string and that fixed it. Log the first few characters of your encodedImage variable to see what you’re actually getting. Also double-check that your Odoo field accepts base64 data - some attachment fields expect different formats. If you’re still stuck, try manually encoding a small image and sending it through the same workflow. That’ll help you figure out if it’s the encoding or the Odoo integration that’s broken.

You’re probably already getting base64 data from n8n’s binary storage and trying to convert it again. When n8n stores binary data, the data property is already the base64 string. Your code should work fine - imageData.data already returns base64 encoded content. I’ve hit this same issue with external APIs that expect base64. Check if your Odoo endpoint actually receives the data correctly. Sometimes it’s not the encoding - it’s how Odoo processes the attachment field. Add some debugging to check the actual length and format of your encodedImage variable before sending. Also, some Odoo versions are picky about base64 format. Make sure you’re not including data URI prefixes like data:image/jpeg;base64, unless your Odoo config specifically needs them.