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

Hi everyone! I need help with base64 encoding in n8n. I’m trying to take an image that I downloaded from an API and convert it to base64 format so I can send it to Odoo.

I’ve been working on this for hours but can’t get it right. Here’s what I’m trying to do:

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

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

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

// Get today's date
const currentDate = new Date().toISOString().substring(0, 10);

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

The image comes from an HTTP request node that downloads it from an external service. The file details show:

  • Format: JPEG
  • Size: around 50KB
  • Has proper mime type

But when I try to upload this to Odoo, it doesn’t work properly. Am I handling the base64 conversion correctly? Any suggestions would be really helpful!

The issue might be how n8n stores binary data. When I worked with Odoo integrations, the problem was usually how the binary object gets structured after HTTP requests. Instead of directly accessing imageData.data, check what format the binary data is actually in first. Sometimes n8n wraps it in a buffer that’s already base64 encoded, other times it’s raw binary that needs conversion. Log the type and structure of your binary data first:

console.log('Binary data type:', typeof imageData.data);
console.log('Is buffer:', Buffer.isBuffer(imageData.data));

Odoo usually wants clean base64 without data URI prefixes. If your current approach isn’t working, the binary data might already be in the wrong format from the HTTP node. Try using n8n’s built-in base64 conversion functions or make sure your HTTP request node returns binary data properly. Keep the MIME type separate from the actual image data.

check your http node settings - it might be downloading as text instead of binary, which breaks everything. set “response format” to “file”, not “json”. i had this exact problem last week and wasted hours looking in the wrong place.

I’ve been doing similar integrations for years and n8n’s binary data handling is honestly a nightmare. It’s not just your code - n8n overcomplicates these workflows.

Skip the buffer conversion debugging and use Latenode instead. Set up your API call, handle the binary response, convert to base64, and push to Odoo - all in one clean workflow.

Binary data actually works properly in Latenode. No weird buffer issues or formats changing between versions. You get real error handling and logging too, so you can see what’s happening with your images.

I migrated a similar Odoo integration last month. Went from 6 nodes with custom JavaScript to 3 simple steps. Base64 conversion just works without manual buffer nonsense.

Check it out: https://latenode.com

Had the same problem with binary data in n8n. You’re probably accessing the data property wrong without handling the buffer conversion. n8n’s binary data needs to be converted from buffer to base64 string.

Try this:

const imageData = $input.first().binary?.file;
if (!imageData) {
  throw new Error("Binary content not found");
}

// Convert buffer to base64 string
const encodedImage = Buffer.from(imageData.data, 'base64').toString('base64');

You might also need imageData.data.toString('base64') depending on how your workflow structures the binary data. Odoo’s really picky about base64 format - don’t include data URI prefixes like data:image/jpeg;base64, unless Odoo wants them. Test with a simple base64 string first to make sure your Odoo integration works.

check if odoo wants the mime type prefix or just raw base64. you might need to strip the header from n8n’s binary data. also try imageData.data.toString('base64') instead of accessing .data directly - n8n’s buffer handling can be inconsistent between versions.

Your binary handling looks right, but this is probably an Odoo field issue, not n8n encoding. I’ve hit this before when uploading images to Odoo through APIs. First, check if your Odoo field wants pure base64 or needs special formatting. Some image fields auto-decode base64, others need manual processing in Odoo. Debug by checking your encoded string length vs the original file - base64 should be about 33% bigger. Make sure you’re hitting the right field type too - attachment fields work differently than binary fields. Also, Odoo often wants the filename and content type sent separately from the base64 data. Check your model definition to see what’s actually required for image uploads.

Check your HTTP request node’s response format first. n8n often defaults to text parsing when downloading images, which corrupts the binary data before your JavaScript even sees it. This changes how the binary object is structured. Also check if imageData.mimeType shows what you actually downloaded - if you see text/plain instead of image/jpeg, that’s your HTTP node problem right there. For Odoo, test your base64 string by decoding it back to a file on your machine first. If that decoded image is corrupted or empty, it’s definitely n8n’s binary handling that’s broken, not Odoo.