Hey everyone! I’m having trouble with a workflow in n8n where I need to take an image file from an HTTP request 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.
I’m trying to process binary data from a media download node and transform it into the correct base64 format. Here’s what I’m currently using:
// 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 record
const currentDate = new Date().toISOString().substring(0, 10);
// Prepare output for next workflow step
return {
json: {
photo_field: encodedFile,
date_field: currentDate,
comment_field: $json.comment_field || "",
},
binary: {
attachment: fileData
}
};
The binary data I’m working with has these properties:
- Filename: abc123def456ghi789
- Path: mediafiles/2025/1/987654
- Type: jpeg
- Content-Type: image/jpeg
- Size: 48.2 kB
Am I handling the base64 conversion correctly? Any suggestions would be really helpful!
The encoding looks right, but I think the problem is how Odoo expects the data format. I’ve dealt with similar integrations before - Odoo’s binary fields are picky about how they get data. Your code assumes fileData.data is already base64, which it usually is in n8n, but you should double-check by looking at the actual content type. Add a validation step to make sure the data’s properly encoded before sending it to Odoo. Also, some Odoo setups need binary data without any data URI prefixes - just the raw base64 string. Try sending a small test image first to see if it’s an encoding issue or if Odoo’s having trouble processing what you’re sending.
check if your media download node is returning binary data correctly. sometimes the issue isn’t in the conversion but in how the file gets pulled. try adding console.log(Object.keys($input.first())) to see what’s available. also, odoo can be finicky about file size limits on binary fields.
you’re missing the base64 conversion step. fileData.data should already be base64, but double-check with Buffer.from(fileData.data, 'base64').toString('base64'). also, odoo sometimes needs the mime type prefix like data:image/jpeg;base64,${encodedFile} depending on which field you’re using.