Read/Write Files from Disk Node and Multi-Webhook Workflow

Describe the problem/error/question

I have a workflow with multiple webhooks, each for a unique user.
The workflow can be called by multiple users at the same time. For each execution of the workflow, I need to take JSON data that the user sent to the webhook, and store it in a file for later user in the workflow or by the separate error workflow.

For example, the users’ email address is part of the payload to the webhook. I’m using the Read/Write Files from Disk Node to write the JSON data in binary to file.txt. If there is an error with the main worklow, the error workflow will read file.txt to get the email address and uses sendgrid node to sent an email.

With each execution of the workflow, does the ‘Read/Write Files from Disk Node’ write a file (file.txt) that is isolated from other executions of the workflow?

I’m trying to avoid file.txt being overwritten by another file.txt.

How do I ensure the uniqueness and isolation of file.txt across executions that happen at the same time on the same workflow?

Soemthing tells me instead of hardcoding the name ‘file.txt’, I need to use a dynamically generated value, like my execution ID? But how will the error workflow know the execution ID of the main workflow?

Information on your n8n setup

  • n8n version: 1.41.0
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): cloud
  • Operating system:

Okay, I think I have the solution that I need.

On the main workflow, in the 'Read/Write Files from Disk Node’ that writes the file, I use {{ $ + “.data” }} for the File Path and Name.

On the error workflow, in the 'Read/Write Files from Disk Node’ that reads the file, I used {{ $ + “.data” }} for the File Path and Name.

I noticed that $ is the execution id of the main workflow, that called the error workflow.

Since each instantiation of a single workflow has a unique execution ID, I’ve solved my file uniqueness issue.

1 Like

hello @ManOnFire1978

Yes, you can use the $ from the executed workflow in your error workflow. Don’t forget to clean files after use, otherwise, you can have dozens of files.


Thank you!

I was wondering about clean up. I don’t see a delete files node; any suggestions on the best way to remove the file at the end main and/or error workflow?

It doesn’t appear this will work How to delete local file, as I am using n8n cloud and not n8n self-hosted.

Wel… On the cloud there is no such possibility :face_with_hand_over_mouth:

Actually, local files are something that should not be possible to work with on the cloud instance.

@Jon maybe you have thoughts about how to deal with it, as there is no Execute Command node there.

Please don’t remove the read/write node on the n8n cloud; it’s functionality I need to make my workflow work. :slight_smile:

I do want to be responsible and clean up files, though.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.