Sharath Kirani
Sharath Kirani

Reputation: 105

How to upload a subfolder in shared google drive using python?

Need to know how to do the same in shared drive.

I was able to create a subfolder in my drive using:

file_metadata = {
            'supportsAllDrives':True,
            'parents': ['twLBZwLdxfBKTEX0VUUr6'],
            'name': "new folderrrrr sub",
            'mimeType': 'application/vnd.google-apps.folder',
        }

file = DRIVE.files().create(body=file_metadata,
                            fields='id', supportsAllDrives=True, supportsTeamDrives=True).execute()```

Upvotes: 1

Views: 1048

Answers (1)

Jacques-Guzel Heron
Jacques-Guzel Heron

Reputation: 2598

I grasp that you want to upload a folder filled with files in a shared drive. If that isn't your question, please forgive me. To accomplish that you'll need editing permission to be able to write into that shared drive. With that on mind, your operation can be divided into two steps:

  1. First you want to create a folder inside the shared drive in a way similar as this one. As the parents[] you have to use the id property of the shared drive (you can get it by using the LIST method).
  2. After that you'll have to upload every file, one by one, with a code akin this one. You'll need to use the identifier of the folder created on the previous step and the appropriate MIME type.

For both operation you must use the CREATE method with the supportsAllDrives parameter set to true (this requirement is only needed until the first of June of 2020 as described on the linked documentation). You can read here how to set up a working Drive API environment for Python if you don't have one already. If you have any doubt or request additional help, please don't hesitate to comment on my answer.

Upvotes: 1

Related Questions