Write then read failing

What is wrong with this flow?
It writes to a file and then reads it again. At least it should. It fails to find the file.

{
  "nodes": [
    {
      "parameters": {
        "functionCode": "items[0].json = [];\nreturn items;"
      },
      "name": "Data",
      "type": "n8n-nodes-base.function",
      "position": [
        630,
        220
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "fileName": "old.json"
      },
      "name": "Write",
      "type": "n8n-nodes-base.writeBinaryFile",
      "typeVersion": 1,
      "position": [
        790,
        220
      ]
    },
    {
      "parameters": {
        "filePath": "old.json"
      },
      "name": "Read",
      "type": "n8n-nodes-base.readBinaryFile",
      "typeVersion": 1,
      "position": [
        950,
        220
      ]
    }
  ],
  "connections": {
    "Data": {
      "main": [
        [
          {
            "node": "Write",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write": {
      "main": [
        [
          {
            "node": "Read",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

@tcurdt The read and write node work with binary data, so you gotta transform the data to binary before using them. See example below:

   {
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "items[0].json = { hola: 1 };\nreturn items;"
      },
      "name": "Data",
      "type": "n8n-nodes-base.function",
      "position": [
        450,
        300
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "fileName": "old.json"
      },
      "name": "Write",
      "type": "n8n-nodes-base.writeBinaryFile",
      "typeVersion": 1,
      "position": [
        810,
        300
      ]
    },
    {
      "parameters": {
        "filePath": "old.json"
      },
      "name": "Read",
      "type": "n8n-nodes-base.readBinaryFile",
      "typeVersion": 1,
      "position": [
        980,
        300
      ]
    },
    {
      "parameters": {
        "mode": "jsonToBinary",
        "options": {}
      },
      "name": "Move Binary Data",
      "type": "n8n-nodes-base.moveBinaryData",
      "typeVersion": 1,
      "position": [
        630,
        300
      ]
    },
    {
      "parameters": {
        "options": {
          "keepSource": false
        }
      },
      "name": "Move Binary Data1",
      "type": "n8n-nodes-base.moveBinaryData",
      "typeVersion": 1,
      "position": [
        1170,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Data": {
      "main": [
        [
          {
            "node": "Move Binary Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write": {
      "main": [
        [
          {
            "node": "Read",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read": {
      "main": [
        [
          {
            "node": "Move Binary Data1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Move Binary Data": {
      "main": [
        [
          {
            "node": "Write",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
1 Like

@tcurdt Just updated the example cuz after you read the data you gotta transform it from binary to json so that you can use it.

1 Like

I kind of figured that is has something to do with not having the correct property populated - but I would then expect it to write an empty file and also read an empty file.

I would consider the current behaviour even a bug.
If it is not then at least the write should fail, too.

But at least I got it working now. Thanks.

Yes, I agree. Failing when there are no binary properties or the binary property with the defined name does not exist would make more sense. I will change it.

1 Like

The write node will now error when data is missing.

1 Like

But when I provide an empty object it will still clear the file?
I use it that way in an workflow now.

(I am more in the “no data => file size 0” camp)

The only difference is now, that in cases in which it did before simply go on and do nothing, it now errors. As it before did something (clear the file) it still will.

https://github.com/n8n-io/n8n/commit/f2236ba38c106cbb457764b973fc92ead3b207fa

1 Like

Got released with [email protected]

1 Like