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!
Code looks mostly right, but there’s likely an issue with how you’re grabbing the binary data. In n8n, fileData.data
is usually already base64 encoded, so that part should be fine. I’ve hit this before though - sometimes you need to handle the encoding explicitly. First, log the actual fileData
content to see what you’re dealing with. Also check that your Odoo field can handle binary data properly. Some fields want raw base64, others need the full data URI format with mime type prefix. I’d test both approaches to see what works for your specific field.
Skip $input.first()
and go straight to items[0].binary.attachment
- it’s way more reliable in n8n workflows. You’re not actually converting anything, just extracting what’s already there. Add a real conversion step: const encodedFile = Buffer.isBuffer(fileData.data) ? fileData.data.toString('base64') : fileData.data;
to handle both cases. Check your HTTP request node too - make sure it’s downloading as binary attachment, not just grabbing URLs. Debug the data structure first with console.log(typeof fileData.data, fileData.data.length)
so you can see what you’re working with before converting.
Had the same issue with Odoo recently. n8n handles binary data weirdly depending on how it’s retrieved. Try $binary.attachment.data
instead of the input object. Check what format you’re actually getting - sometimes it’s a Buffer instead of base64. If so, convert it with Buffer.from(fileData.data).toString('base64')
. Odoo’s also picky about field types. Attachment fields vs binary fields expect different formats. Log the data type at each step to see where it’s breaking.
Quick fix - try $node["YourNodeName"].binary.attachment.data
if $input.first()
isn’t working. Make sure your Odoo field’s set to binary, not text. I’ve seen encoding get screwed up during transfer, so add validation to check if the base64 string length matches what you expect.
Your binary data access pattern might be the issue. Skip $input.first().binary?.attachment
and try $binary.attachment
or items[0].binary.attachment
instead. I’ve hit problems where the input wrapper doesn’t expose binary data properly in some workflow setups. Also watch the encoding format - n8n sometimes stores binary as Buffer objects instead of base64 strings. Check typeof fileData.data
first. If it returns ‘object’, you’ll need to convert it. And make sure your HTTP request node downloads binary content, not just URLs or metadata.