Uploading multiple files to multiple Gdrive folders

Describe the issue/error/question

I’m a newb to n8n.

I’ll quickly describe what my intended functionality is:

  1. read a series of DB records
  2. Create a google drive folder named the same as the DB item’s id
  3. Read a folder of files on disk that has the same name as the db item id
  4. Upload each local folder’s contents to the corresponding folder name in google drive

Essentially I want to upload a series of folders/files into gdrive and have the relationships match.

Like this:



Right now only 1 file gets uploaded to each folder and the rest get dumped into the google drive root folder.

How would I go about setting up my workflow so I can iterate over each folder properly?

What is the error message (if any)?

Please share the workflow

Hey @Justin_Young, welcome to the community :tada:

I suspect your “Read Binary Files” node reads multiple items? If so, the problem would be caused by your expression {{$node['createFolder'].json["id"]}} in the final Google Drive node. For the first item this node receives, it would look up the ID field of the first item on the createFolder node which works fine. However, for the second item this node receives it would look up the ID field of the second item on the createFolder node which causes the mismatch from the sounds of it.

Now from the sounds of it you’d create multiple folders on each execution of the workflow, meaning we’d need to build a loop here (and then process one folder per loop). Looping in n8n is described here: Looping - n8n Documentation

With the loop in place you could then adjust the expression in your final Google Drive to always look at the first item of your createFolder node by prepending it with $item(0) (so {{$item(0).$node['createFolder'].json["id"]}}). This means that for each item your Google Drive node receives, it would look at the first item of the createFolder node (which has an index of 0, hence $item(0).

Looking at your workflow this could look like so when put together (I hope, it’s easy to miss something when not having access to the actual data being processed).

Hope this helps! Let me know if you have any questions on this.

Got it working! Thanks so much :slight_smile: