Skip to content
This repository was archived by the owner on Jul 22, 2021. It is now read-only.
This repository was archived by the owner on Jul 22, 2021. It is now read-only.

How can I upload a file to team drives folder? #149

Open

Description

@mythicc

I already made a python script to upload file to specified folder,
but I can't find the team drive folder by id.

Can anyone give me a hint? Thanks.

Activity

  1. spartako commented on Dec 3, 2018

    @spartako

    Just make sure your credentials have access to that Team Drive, and then add a few more parameters like so:

    file_list = drive.ListFile(
        {
            'q': "'root' in parents and trashed=false",
            'corpora': "teamDrive",
            'teamDriveId': "YOUR TEAM DRIVE ID HERE",
            'includeTeamDriveItems': "true",
            'supportsTeamDrives': "true"
        }
    ).GetList()
    for file1 in file_list:
        print('title: %s, id: %s' % (file1['title'], file1['id']))
    

    Once you get the ID, the process for uploading is as usual

  2. chrisPiemonte commented on Jan 16, 2019

    @chrisPiemonte

    I still can't upload files to team drives folder, but i can list them. This is my code to upload files:

    f = drive.CreateFile({
        'supportsTeamDrives': 'true',
        'teamDriveId': 'XXXXXXXXXXXXX',
        'corpora': 'teamDrive',
        'name' : 'test',
        'includeTeamDriveItems': 'true',
        'mimeType' : 'application/vnd.google-apps.folder',
        'parents': [{
            'kind': 'drive#fileLink',
            'id': 'XXXXXXXXXXXXX',
            'teamDriveId': 'XXXXXXXXXXXXX'
        }]
    })
    
    f.Upload()

    I don't know if this is because of permissions or else, and i don't know how to check it either. Can anyone help me on this ?

  3. bendavis78 commented on Jan 25, 2019

    @bendavis78

    @spartako How do you find the team drive id?

  4. Imoustak commented on Feb 4, 2019

    @Imoustak

    @bendavis78
    The ID of the Team Drive can be found at the last part of its URL

  5. rlkc112358 commented on Feb 8, 2019

    @rlkc112358

    Credits to this StackOverflow Answer

    You have put the supportsTeamDrives:"true" in the wrong place
    the docs https://developers.google.com/drive/api/v2/reference/files/insert specify that it needs to be a query parameter

    Here is my code which worked

    team_drive_id = 'XXXXXXXXXXXXX'
    parent_folder_id = 'XXXXXXXXXXXXX'
    
    f = drive.CreateFile({
        'title': 'test.txt',
        'parents': [{
            'kind': 'drive#fileLink',
            'teamDriveId': team_drive_id,
            'id': parent_folder_id
        }]
    })
    f.SetContentString('Hello World')
    
    f.Upload(param={'supportsTeamDrives': True})
    
  6. hermannsblum commented on Feb 26, 2019

    @hermannsblum

    This seems the right place to ask:

    How can I download a file? Unfortunately, just adding the supportsTeamDrives flag does not help...

    downloaded = drive.CreateFile({'id': file_id, 'supportsTeamDrives': True})
    print('Downloaded content "{}"'.format(downloaded.GetContentString()))
    
  7. rarup1 commented on Feb 27, 2019

    @rarup1

    I am having the same problem. I have searched everywhere but no luck so far. The GET request when I set up my CreateFile as follows seem to omit the teamSupport params:

    file = self.drive.CreateFile(
                                {
                                    'id': fileid,
                                    'supportsTeamDrives': 'true',
                                    'includeTeamDriveItems': 'true'
                                })
    

    This is the Get request captured in my logger:
    INFO:googleapiclient.discovery:URL being requested: GET https://www.googleapis.com/drive/v2/files/1omHKJUACcnyqaSaMJ3kvVsQ3U8E3Cm5Y?alt=json

    I tried setting up as suggested with the nested params to no avail too:

    team_drive_id = XXXXXXX
    file = self.drive.CreateFile(
                                {
                                    'id': fileid,
                                    'parents': [{
                                    'kind': 'drive#fileLink',
                                    'teamDriveId': team_drive_id
                                    }]
                                })
    

    Like the above commenter said the

    drive.ListFile(
                
                            }).GetList() 
    

    works fine.

    Any help in getting it to send the correct Get request would be much appreciated.

    Thanks!

  8. keliomer commented on May 24, 2019

    @keliomer

    @rarup1 you need to add query parameters to the ListFile() call

    ie

    file_list = drive.ListFile({'q':"title='yourfiletitle' and 'parent_id' in parents and trashed=false"}).GetList()

    Without the query params you're not actually looking for anything!

  9. AstronoTech commented on Nov 18, 2019

    @AstronoTech

    I have the exact same question as @rarup1. I know @fergusleahytab has brought modifications to PyDrive, but I am still not sure how to modify @rarup1's code to download files from a shared folder (where to put 'supportsTeamDrives': True if there any need for it). Any help would be deeply appreciated.

    Kind regards,
    Berti

  10. cccat6 commented on Apr 19, 2021

    @cccat6

    I successfully upload the files to Shared Drive (Team Drive) with PyDrive.
    In pydrive/files.py, about line 368. Add a line of code param['supportsAllDrives'] = True
    Which should look like this:
    image

    Last, just simply use these code templet

    f = drive.CreateFile({'title': '<file name, not really necessary>','parents': [{'id': '<your shared drive id>'}]})
    f.SetContentFile(os.path.join(path, '<file in your local>'))
    f.Upload()
    

    Hopes it will help someone.

  11. shcheklein commented on Apr 19, 2021

    @shcheklein

    @cccat6 you could also check the maintained PyDrive2 fork. It has that (and many other fixes) in it.

  12. cccat6 commented on Apr 19, 2021

    @cccat6

    @cccat6 you could also check the maintained PyDrive2 fork. It has that (and many other fixes) in it.

    Ops... I didn't notice there is a PyDrive2. Spends me an hour on positioning the point :(
    Thank you for your inform.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions