I run a self-hosted n8n v1.9x.
The Read/Write Files from Disk node reads a JPEG just fine (I can preview/download it in the execution). But when I try to push that same file straight into an HTTP Request node (to open-wa),
it sends a 3kbs file with the image name, but it is not a valid image.
$binary.image.data is always undefined, so the payload ends up like:
Docs don’t show how to grab the real file content directly.
After lots of trial-and-error — and with ChatGPT’s help — I found a workaround that works:
// Code node (run once per item)
const field = 'image';
const buf = await this.helpers.getBinaryDataBuffer(0, field); // works even in filesystem mode
const meta = $binary[field];
const b64 = buf.toString('base64');
return [{
json: {
args: {
to: [email protected]',
file: `data:${meta.mimeType};base64,${b64}`,
filename: meta.fileName,
caption: 'Here is the report',
requestConfig: {}
}
}
}];
Placing this Code node between Read/Write Files and HTTP Request finally delivers a valid image (open-wa in my case).
Is the Code node really the only or best practice way to pass a file from Read/Write Files to an HTTP Request in the current binary-filesystem setup? Any cleaner built-in option?
This is a case study, a practical example for my day-to-day of sending the AI analysis and the photo to WhatsApp, of the images that the frigate records internally.
In the future, understanding how n8n gets files in homelab with casaOS, I intend to create more things.
I would be very grateful if you have any material or guidance on how to deal with this.
Thanks in advance!
Thanks @darrell_tw
This opens up the understanding a bit more.
But I still haven’t managed to do it, I’m in the post method.
If I use send n8n binary or as Form-Data, with the file field using n8n binary file.
It gives me;
success = false
error
name = TypeError
message = Cannot read properties of undefined (reading ‘normalize’)
Thanks again for the help. This is really messing with my head. This problem is proof of chatgpt.
Solving this will be the basis for working on another project, using a celestial capture station with “AllSky” with Raspberry Pi. Automatically uploading the captures from the internal HD to Instagram.
(I bought an imported product and the material will still arrive)
Thanks @darrell_tw
I ended up figuring this part out, I was still racking my brains here, and the error was because the text came with /n, for line break.
So I used “{{ ($json.description || ‘’).replace(/\r?\n/g, ’ ') }}”
And it worked.
I’m still racking my brains here, the problem is how to send the image with the n8n Binary File, as you indicated, but inside the args and with the other commands and have the output as openwa expects.