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

Hey everyone! I need help with something that’s been giving me trouble. I’m working on a workflow where I download an image from an API and then need to send it to Odoo as base64 encoded data. The image comes from an HTTP request node but I’m having issues with the base64 conversion process. Here’s what I’ve tried so far:

// 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: {
    image_field: encodedImage,
    date_field: currentDate,
    notes_field: $json.notes_field || "",
  },
  binary: {
    file: imageData
  }
};

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

  • Filename: abc123def456ghi789
  • Path: apifiles/2025/1/987654
  • Type: jpeg
  • Content-Type: image/jpeg
  • Size: 62.1 kB

Am I handling the base64 conversion correctly? Any suggestions would be really helpful!

The .data property should work fine for getting base64. If Odoo’s being picky about format, try adding the data:image/jpeg;base64, prefix. Also make sure your http node output is set to binary mode - otherwise you’ll get weird encoding issues.

I hit the same issue recently with Odoo attachments. Your code looks right, but imageData.data should already have the base64 string if n8n processed the binary data correctly. Sometimes you need to handle the encoding step yourself though.

What fixed it for me was adding a check to make sure the data’s actually base64 encoded before sending to Odoo. Test it by seeing if the string starts with expected base64 characters or try decoding it temporarily. Also, check that your HTTP request node downloading the image has response format set to “File” not “JSON” - that tripped me up at first.

Watch out for Odoo’s field requirements too. Some attachment fields just want the base64 string, others need extra metadata. Double-check your Odoo model docs for the exact format it expects.

I’ve been running a similar workflow for months and hit this exact issue early on. The fix was making sure the binary data is accessible before extracting the base64. Your imageData.data approach looks right, but I’d debug it first. Log the binary object structure: console.log(JSON.stringify($input.first().binary, null, 2)). The binary data sometimes gets nested differently based on how the HTTP node processed it. One thing that got me - Odoo wants clean base64 without newlines or whitespace. Add .replace(/\s/g, '') to strip any formatting characters that slip in during conversion. Also check your Odoo API endpoint logs to make sure it’s actually receiving the data correctly. Sometimes the problem’s on the receiving end, not the encoding.