Subject: Issue with Convert to File and Code Nodes Returning Empty Binary Output in n8n 1.81.4 + Workflow Goal Explanation
Dear n8n Support Team,
I hope you’re doing well. I’m writing to report an issue with n8n version 1.81.4 (self-hosted via Docker) that I’ve been troubleshooting extensively, and I’d appreciate your assistance in resolving it or confirming a potential bug. Additionally, I’d like to explain the purpose of my workflow to provide context, as you might be able to suggest an alternative approach.
Problem Description
I’m building a workflow to write a JSON object (e.g., {“message_id”: 116}) to a file (/home/node/.n8n/message_ids.json) with the ability to append new entries. However, I’m encountering issues where the Convert to File node and Code node (when returning binary data) output an empty object [{}], preventing the file from being written.
Workflow Goal and Context
The purpose of saving these message_id values to a file is to manage a Telegram bot’s scheduled messages. Here’s the full process I’m trying to achieve:
- Step 1: Sending Messages
The bot sends a random message to a Telegram chat every Monday and Thursday at 9:00 AM (Moscow time) using a Schedule Trigger (0 0 9 * * 1,4), a Code node to select a random message, and a Telegram node. The message_id of each sent message is returned by the Telegram API. - Step 2: Saving Message IDs
I want to save each message_id to a file (message_ids.json) as a JSON line (e.g., {“message_id”: 116}\n) with appending enabled. This file would act as a log of sent messages. - Step 3: Deleting Messages
At 15:00 on the same days, a second workflow would read the message_ids.json file, extract the message_id values, and use the Telegram API (deleteMessage) to remove these messages from the chat. This ensures the messages are only visible from 9:00 to 15:00.
The issue arises in Step 2: I can’t reliably save the message_id to a file due to the problems described below.
Technical Details
- n8n Version: 1.81.4 (self-hosted, Docker image: n8nio/n8n:1.81.4)
- Docker Setup: Running with --user 1000:1000 and volume n8n_data:/home/node/.n8n. Directory permissions are drwxr-xr-x 1000:1000, and write access for the node user is confirmed.
- Current Date: March 8, 2025
Scenario 1: Using Convert to File
- Code Node:
javascript
const messageId = $json[“message_id”];
return [{ json: { message_id: messageId } }];
- Output: [{“json”: {“message_id”: 116}}]
- Convert to File Node:
- Operation: toJson
- Mode: All Items to One File
- Put Output File in Field: data
- Options: fileName: message_ids.json, encoding: utf8, format: true
- Result: Output is [{}], and no binary.data is generated.
- Read/Write Files from Disk Node:
- Operation: write
- File Name: /home/node/.n8n/message_ids.json
- Data Property Name: data
- Options: append: true
- Log Output: “The file /home/node/.n8n/message_ids.json is not writable”, though I suspect this is due to the empty input from Convert to File.
Scenario 2: Using Code Node with Binary
- Code Node:
javascript
const messageId = $json[“message_id”];
const jsonString = JSON.stringify({ message_id: messageId }) + ‘\n’;
const base64String = btoa(jsonString);
return [{
json: {},
binary: {
data: {
data: base64String,
mimeType: ‘application/json’,
fileName: ‘message_ids.json’
}
}
}];
- Result: Output is [{}]. The binary field appears to be stripped or blocked by the sandbox.
- Note: Returning json with base64String works (e.g., [{“json”: {“base64String”: “eyJtZXNzYWdlX2lkIjoxMTZ9Cg==”}}]), but adding binary breaks it.
Observations
- The Convert to File node fails to produce binary.data in both toJson and toText modes, even with correct inputs.
- The Code node cannot return a binary object, possibly due to sandbox restrictions in 1.81.4.
- File permissions are correct (1000:1000, 755), so the issue isn’t disk access-related.
Questions
- Is this a known bug in n8n 1.81.4 with the Convert to File or Code nodes?
- Are there workarounds in 1.81.4 to save message_id values to a file (or another storage method) for my use case?
- Would upgrading to the next version (1.82.1) resolve this, or should I wait for a stable release?
- Given my goal (tracking message_id for scheduled deletion), is there an alternative approach in n8n—perhaps using variables, a database, or another method—to avoid file writing altogether?
Additional Info
- I’ve tested extensively: updating Docker images, adjusting permissions, and trying various node configurations.
- Logs show “The file is not writable”, but this seems to be a symptom of missing binary.data.
- My workflow sends Telegram messages successfully; the bottleneck is saving the message_id for later deletion.
I’d greatly appreciate your insights, recommendations, or confirmation of this behavior. If this is a bug, I’m happy to provide more details or assist in debugging. Alternatively, if there’s a better way to achieve my goal (e.g., storing message_id without files), I’d love to hear your suggestions. Thank you for your time and support!