How to upload to multiple folders with Google Drive

Hello !

I would like to know if this is possible to upload a file to multiple google drive folders with only one Google Drive Node. I tried to put multiple Parents but it throws me a 403 error Increasing the number of parents is not allowed. Why am I able to set multiple Parents if it only works with one ?

Hi @Madriax, I don’t know the definitive why multiple parents are implemented the way they are - I suspect it might have been possible at the time of development.

If using a single Google Drive node is a requirement, you could just create multiple items with the desired parent names. The Google Drive node would then run once for each item.

Example Workflow
{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "return [{\n  json: {\n    parent_id: '1xcIkD3QYDWm6AlN2mWU7eH9agEslfCP_'\n  }\n}, {\n  json: {\n    parent_id: '1up9cIAOzK__0UEuagVnN-lEN7_bxivKQ'\n  }\n}]"
      },
      "name": "Set Google Drive Parents",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "url": "https://unsplash.com/photos/gRxpaCFdx4I/download?ixid=MnwxMjA3fDB8MXxhbGx8OHx8fHx8fDJ8fDE2MzU4NjUyNTk&force=true&w=640",
        "responseFormat": "file",
        "options": {}
      },
      "name": "Download Sample File",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "binaryData": true,
        "name": "=image.jpg",
        "parents": [
          "={{$json[\"parent_id\"]}}"
        ],
        "options": {}
      },
      "name": "Google Drive",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 1,
      "position": [
        850,
        300
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "28",
          "name": "Google Drive account"
        }
      }
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Set Google Drive Parents",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Google Drive Parents": {
      "main": [
        [
          {
            "node": "Download Sample File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Sample File": {
      "main": [
        [
          {
            "node": "Google Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Hi @MutedJam

Thank you for helping me ! As I receive multiple binary files, I had to adapt the Function Node to split the binaries in the same function so here’s my final function node which is working:

const folders = ['xxx', 'xxx']
let results = []

for (let i=0;i<folders.length;i++) {
  results.push(
    Object.keys(items[0].binary).map(key => {
      return {
        json: {
          parent_id: folders[i]
        },
        binary: {
          data: items[0].binary[key],
        }
      }
    })
  )
}
return [].concat(...results)

I don’t know if I could have done better, tell me if you see another solution. I tried to use the Item Lists Node to split binaries but it doesn’t seem to work so I really hope that someday we will be able to split binaries without a function Node, this would be great!

1 Like

Happy to hear you find a way to make this work for you and thanks a lot for sharing your snippet!

As for your feedback on the Item Lists node, could you put this into a separate feature request? This way, other community members can vote on it (and contributors and the n8n team will have visibility on the request).

1 Like