2

I'm trying to upload a file to a specific Team Drive via the Python API, but am struggling with where to specify the teamDriveId. I'm working with Drive v3.

Here is the function I am working with:

def upload_file(self): # self.service: Google Drive Hook - works well for other functions # self.drive_id: Id of Team Drive I am trying to upload to metadata = {'name': 'sample.txt'} media = MediaFileUpload('sample.txt', mimetype = 'text/plain') upload = self.service.files().create(body=metadata, supportsTeamDrives=True, media_body=media, fields='id).execute() 

I have attempted to put this in both the create() function and the metadata JSON as {'parents': self.drive_id} but this either return an Unexpected keyword argument: teamDriveId or the file will just upload to my personal drive.

I do not have any folders inside the Team Drive I am attempting to work with. I looks like I could set {parents': <teamDrive_folderId>} but I am hoping to find a solution where I don't have to specify a folder and can just put files in the root of the Team Drive.

Any suggestions would be greatly appreciated.

1 Answer 1

6

Setting parents to the Team Drive's ID works for me and inserts the file into the root of the Team Drive. Minimal example:

# media is a `MediaFileUpload` instance service.files().create( supportsTeamDrives=True, media_body=media, body={ 'parents': ['0AILoX...'], # ID of the Team Drive 'name': 'foo.txt' } ).execute() 

Are you sure that you got the right ID?

Sign up to request clarification or add additional context in comments.

4 Comments

Definitely the right ID. Looks like the issue was I was not passing the DriveId in a list. Works now, thanks!
Great answer! It works for me, as well. But what if I have a folder inside that TeamDrive? What should I pass / set to upload into the folder within a TeamDrive? Thanks!
I think you should just be able to use the folder's ID in the parents list. Didn't test it, though :)
Thank you so much for this! I was trying to use the Golang package to upload files with a service account... I'm not exactly sure where they were going before I started supplying this field - but they were definitely going somewhere. Supplying the teamdrive ID in the parents property put the files where I expected.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.