PyDrive
PyDrive copied to clipboard
How can I update a file while keeping its revision history?
Hi - The Google Drive API apparently offers support for publishing a revised version of a file while keeping its history according to https://developers.google.com/drive/api/v3/manage-revisions. How can I use this feature with PyDrive?
Thanks!
I am also interested in this - was any resolution found?
OK I think I've worked it out - something like this works:
from pydrive.drive import GoogleDrive
drive = GoogleDrive(gauth)
file1 = drive.CreateFile({'title': 'Hello.txt'}) # Create GoogleDriveFile instance with title 'Hello.txt'.
file1.SetContentString('Hello World!') # Set content of the file from given string.
file1.Upload() # new file with contents = 'Hello World!'
file1.SetContentString('Hello World1!')
file1.Upload() # new version with contents = 'Hello World1!'
file2 = drive.CreateFile({'id': file1['id']})
file2.SetContentString('Hello World2!')
file2.Upload() # file now has new version with contents = 'Hello World2!'
I think this just updates the contents of the file, but does not snapshot a revision - eg you can go back to the version you updated yesterday etc, would be very interested to know if this is possible with pydrive - cant seem to find any documentation on it
Is there any progress on this? I would really love to see such a feature
This is apparently not implemented in Pydrive. The official google drive api also has no example how to create revisions, however I will try to figure this out in the next days.
I figured it out with the official google drive api: You merely have to use the file update function: https://developers.google.com/drive/api/v3/reference/files/update A new revision is created automatically for you which can be used with several functions: https://developers.google.com/drive/api/v3/reference/revisions PyDrive could be extended by them or you switch directly to the official API instead
OK I think I've worked it out - something like this works:
from pydrive.drive import GoogleDrive drive = GoogleDrive(gauth) file1 = drive.CreateFile({'title': 'Hello.txt'}) # Create GoogleDriveFile instance with title 'Hello.txt'. file1.SetContentString('Hello World!') # Set content of the file from given string. file1.Upload() # new file with contents = 'Hello World!' file1.SetContentString('Hello World1!') file1.Upload() # new version with contents = 'Hello World1!' file2 = drive.CreateFile({'id': file1['id']}) file2.SetContentString('Hello World2!') file2.Upload() # file now has new version with contents = 'Hello World2!'
Thanks! Your Code now run exactly i need, create a revision history!