Error: Write Binary FIle

Setup:
Docker
[email protected]

in docker-compose.yml:

n8n:
  volumes:
    - ${DATA_FOLDER}/local-files:/files

image

Error:

I’m unable to figure out where i did wrong in this flow.

Kindly advise.
Thanks.

I think you are misunderstanding what is happening. So here a more detailed explanation:

So first, why you are actually adding those lines to the docker file. What you do there is that you say that the folder ${DATA_FOLDER}/local-files should be made available inside of the n8n-docker-container as/files. Both values you can change to whatever value you want.
In this case, it uses a variable and so the actual location of the folder on your host-system depends on what you have DATA_FOLDER set to. If you have it set like in the example to /root/n8n/ the full path would be /root/n8n/local-files. That was however just an example. You should set it to wherever you want the files to be saved to. So you could also do

n8n:
  volumes:
    - /home/shrey/n8n-files:/files

Now you have one folder inside of n8n that you can write to and if you do two things will happen:

  1. The files will be persisted between n8n restarts
  2. You can easily access those files on your host-machine via the folder you defined.

So now you actually have to use that folder. Meaning in the “Write Binary File” Node under “File Name” you do not write “filename.xlsx” you write “/files/filename.xlsx”.

Then it everything will work fine.

1 Like

Hi @jan, thanks for your response.

I tried what you suggested:

Still, the same error :confused:

@jan, it seems to work now, after i further modified the docker-compose.yml:

n8n:
  volumes:
    - ${DATA_FOLDER}/.n8n/local-files:/files

Anything i should have differently in the initial setup, for this issue to not have come up?

1 Like

Glad to hear that it works now.

The only things I can think of is that you have to make sure that this folder exists (even though normally docker automatically creates it if not) and that you can write to it.

1 Like

I have the same problem.
I run n8n on in docker on a synology NAS.
I mounted a folder “Share” and another folder which I used successfully for storing files from docker images for calibre…
This are the binds from the hostconfig.json of the container:

“Binds”: ["/volume1/Share:/pubshare:rw", “/volume1/docker/n8n-fileshare:/fileshare:rw”],

/volume1/Share allows write access for everyone.

I get the same error as shrey.

Error: EACCES: permission denied, open '/pubshare/file.json'
{
  "name": "Read Email, Parse Body as JSON",
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        210,
        500
      ],
      "disabled": true
    },
    {
      "parameters": {
        "postProcessAction": "nothing",
        "format": "resolved",
        "options": {}
      },
      "name": "IMAP Email",
      "type": "n8n-nodes-base.emailReadImap",
      "typeVersion": 1,
      "position": [
        190,
        300
      ],
      "credentials": {
        "imap": "OutlookIMAPCREDENTIALS"
      }
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$node[\"Set Email Fields\"].json[\"SUBJECT\"]}}",
              "value2": "N8N-123-WF: Test"
            }
          ]
        }
      },
      "name": "IF N8N-123-WF: Test",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        590,
        300
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "FROM",
              "value": "={{$node[\"IMAP Email\"].json[\"from\"][\"text\"]}}"
            },
            {
              "name": "TO",
              "value": "={{$node[\"IMAP Email\"].json[\"to\"][\"text\"]}}"
            },
            {
              "name": "RECEIVED",
              "value": "={{$node[\"IMAP Email\"].json[\"date\"]}}"
            },
            {
              "name": "SUBJECT",
              "value": "={{$node[\"IMAP Email\"].json[\"subject\"]}}"
            },
            {
              "name": "BODY",
              "value": "={{$node[\"IMAP Email\"].json[\"text\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set Email Fields",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        390,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "item = $node[\"IF N8N-40014-WF: Test\"].json[\"BODY\"];\nobj = JSON.parse(item);\nreturn obj;"
      },
      "name": "Parse Body",
      "type": "n8n-nodes-base.functionItem",
      "typeVersion": 1,
      "position": [
        790,
        280
      ]
    },
    {
      "parameters": {
        "functionCode": "items[0].binary = {\n  data: {\n    data: new Buffer(JSON.stringify(items[0].json, null, 2)).toString('base64')\n  }\n};\nreturn items;"
      },
      "name": "Make Binary",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        990,
        280
      ]
    },
    {
      "parameters": {
        "fileName": "/pubshare/file.json"
      },
      "name": "Write Binary File1",
      "type": "n8n-nodes-base.writeBinaryFile",
      "typeVersion": 1,
      "position": [
        1230,
        280
      ]
    }
  ],
  "connections": {
    "IMAP Email": {
      "main": [
        [
          {
            "node": "Set Email Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF N8N-40014-WF: Test": {
      "main": [
        [
          {
            "node": "Parse Body",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Email Fields": {
      "main": [
        [
          {
            "node": "IF N8N-40014-WF: Test",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Body": {
      "main": [
        [
          {
            "node": "Make Binary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Make Binary": {
      "main": [
        [
          {
            "node": "Write Binary File1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {},
  "id": "1"
}

Sorry, but I have sadly no experience with synology NAS or running Docker on it. So can not be much of a help here. The only thing I know is that n8n is not doing anything special. It is using the default Node.js write functionality. So if it says that it can not write then the reason is exactly that. Meaning something on a lower level (outside of n8n) is wrong.

So if you are sure that the setup is correct then the only other thing I can think of is that the access rights of that folder are to restrictive. In this case you can simply open them up with something like: chmod 777 -R /volume1/Share.

Hope that helps!

Thanks for your quick reply, so you say that the bind looks good. A Synology is also not much more than a Unix box with docker :wink:

I will check the permissions via ssh and see if that works. :slight_smile:

1 Like