How to send a note to recipients for an uploaded file to Google Drive?

347 views Asked by At

I am with pyDrive to upload files to my Google Drive. I am able to upload files to any specific folder.

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive

gauth = GoogleAuth()
gauth.LocalWebserverAuth()

drive = GoogleDrive(gauth)

file1 = drive.CreateFile({'title': 'myfile.txt', 'parents': [{"kind": "drive#fileLink","id": {FOLDER_ID}}]})
file1.SetContentFile('myfile.txt')
file1.Upload()

How can I share the uploaded file with other people and send a note to the recipients either using pyDrive or official Google Drive REST API?

2

There are 2 answers

0
Peter On

This is available in pydrive via InsertPermission.

The act of creating a permission for a user or group email address will by default send a sharing email to that user or group.

See the Drive API documentation on creating permissions for more info.

0
Robin Nabel On

This can be done using Handling special metadata, more specifically: InsertPermission.

You can share a document with a user (using their email address) like so:

# Add a read permission for the user with the specified email address.
permission = file1.InsertPermission({
                        'type': 'user',
                        'value': '<[email protected]>',
                        'role': 'reader'})


# You can check which permission settings a file has:
print(file1['permissions'])

Replace reader with writer if you want give the user write permission.

InsertPermission accepts all flags described in the official API docs.

Note: PyDrive uses v2 of the Google Drive API.