Hey everyone, I need help with something that’s been driving me crazy for hours. I’m trying to take an image file that I downloaded using an HTTP node (from an API service) and convert it to base64 format so I can send it to Odoo. The problem is my code isn’t working properly and I can’t figure out what’s wrong.
Here’s what I’m currently using in my function node:
// Extract binary content from previous workflow step
const fileData = $input.first().binary?.attachment;
if (!fileData) {
throw new Error("Binary content not available");
}
// Convert binary to base64 format
const encodedFile = fileData.data;
// Create timestamp for current day
const currentDate = new Date().toISOString().substring(0, 10);
// Prepare output for next workflow node
return {
json: {
custom_image_field: encodedFile,
work_timestamp: currentDate,
additional_comments: $json.additional_comments || "",
},
binary: {
attachment: fileData
}
};
The binary data I’m working with is a JPEG image (about 50KB) that gets downloaded successfully. Has anyone dealt with this kind of file encoding issue in n8n workflows before? Any suggestions would be really appreciated!
This is super common with n8n’s binary handling. Your code looks right, but there’s likely an issue with how you’re accessing the binary data. The binary structure changes depending on your HTTP node setup. Don’t assume the binary key is ‘attachment’ - log the entire binary object first: console.log(Object.keys($input.first().binary)) to see what keys actually exist. Also, some APIs return binary data that’s already base64 encoded, others return raw binary. Check the content-type header from your HTTP response and handle encoding based on that. For raw binary, use Buffer.from(fileData.data).toString('base64'). For already encoded data, you might just need to clean it up. One more thing - set your HTTP node’s ‘Response Format’ to ‘File’ instead of ‘String’ when downloading images. This ensures proper binary handling from the start.
n8n’s binary data handling gets weird with Odoo. Don’t use fileData.data directly - grab the raw buffer first, then convert it. I had luck with const rawBuffer = Buffer.from(fileData.data, fileData.mimeType.includes('base64') ? 'base64' : 'binary'); then const encodedFile = rawBuffer.toString('base64');. This way you’re working with actual binary content instead of stuff that might be double-encoded. Also check your Odoo file size limits - some setups have strict caps on base64 attachments that’ll fail silently even when your encoding’s right.
you’re grabbing the data right, but Odoo’s picky about base64 format. check the mime type first - the HTTP node sometimes messes that up. also, Odoo wants clean base64 with no headers or prefixes, so strip everything before the encoded data starts.
Had this exact problem integrating n8n with Odoo for document management. The buffer conversion in n8n’s binary handling is challenging. Try Buffer.from(fileData.data, 'base64') first, then convert back to a base64 string. Also, ensure your binary property name is correct; your HTTP node needs to store the downloaded image with the same binary key name used in your function node. For debugging, add Object.keys($input.first().binary) to check the actual binary properties. In my case, the binary data wasn’t under ‘attachment’ as expected, but instead under a different property name.
Had the same encoding nightmare a few months ago pushing attachments to our CRM. Your issue is that fileData.data in n8n comes pre-encoded as base64, but probably not in the format Odoo wants. What fixed it for me was forcing the buffer conversion: const encodedFile = Buffer.from(fileData.data, 'base64').toString('base64'); - ensures clean encoding. Also check if your Odoo field needs the data URI format with mime type prefix like data:image/jpeg;base64, before the encoded string. I’d log the first 50 characters of your encodedFile to see what you’re getting vs what Odoo expects.
Been dealing with similar integrations for years - the base64 juggling in n8n gets messy fast. You end up debugging JavaScript conversions instead of solving actual business problems.
I switched to Latenode for these workflows since it handles binary data way cleaner. Grab your image from the API and Latenode automatically manages encoding without the buffer conversion headache. The Odoo connector knows exactly what format each field needs.
What sold me was building a document processing pipeline that pulled PDFs from one system and pushed them to three different targets including Odoo. Each system wanted different encoding formats. With n8n I was writing custom functions for every conversion. With Latenode it just worked.
The visual workflow builder shows exactly how your binary data flows between nodes. No more guessing if your base64 string is clean or has weird headers.