How to encode image files as base64 in n8n for Odoo integration

Hey everyone! I’m having trouble with a workflow in n8n where I need to take an image file and convert it to base64 format so I can send it to Odoo. I’ve been working on this for hours and can’t seem to get it right.

I’m downloading images from an API and then need to process them before uploading to Odoo. Here’s what I’m trying to do:

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

if (!fileData) {
  throw new Error('Binary file not found in input');
}

// Convert to base64 format
const encodedFile = fileData.data;

// Create timestamp for record
const timestamp = new Date().toISOString().substring(0, 10);

// Structure output for Odoo
return {
  json: {
    custom_image_field: encodedFile,
    record_date: timestamp,
    description: $json.description || 'No description',
  },
  binary: {
    content: fileData
  }
};

The file I’m working with is a JPEG image (about 50KB) but I’m not sure if I’m handling the base64 conversion correctly. Has anyone successfully integrated file uploads between n8n and Odoo? What’s the proper way to handle binary data conversion in this scenario?

I encountered a similar issue during our Odoo integration. It seems you might be accessing the binary data incorrectly. In n8n, instead of using $input.first().binary, opt for $binary when you’re working with binary data from a previous node. Here’s a sample adjustment: javascript const binaryData = $binary.content; const base64String = binaryData.data; return { json: { custom_image_field: base64String, record_date: new Date().toISOString().substring(0, 10), description: $json.description || 'No description' } }; Additionally, ensure that the corresponding field in Odoo is set as Binary type, not Text. I spent considerable time debugging this because of an incorrect field type on their end. Base64 works seamlessly with JPEG files of that size.

just hit this yesterday! use Buffer.from($binary.data, 'base64').toString('base64') to fix the encoding. also check your odoo field can handle the size - i’ve seen varchar fields cut off base64 strings. test with a small image first to rule out size issues.

Your code structure looks good, but there’s likely an issue with how you’re referencing the binary data. When dealing with binary data in n8n, node context matters. If your binary data comes from an HTTP Request or Read Binary File node, try $node["NodeName"].binary.data instead of $input.first().binary?.content. Also, double-check that your Odoo field actually accepts base64 encoded data. I found it helpful to add a validation step before sending to Odoo - check if the string starts with the right data URL prefix or verify the length matches your file size calculation. Sometimes it’s not n8n that’s the problem but Odoo’s field size limits for binary data.