GAS - upload file to drive with version

270 Views Asked by At

I can use GAS script to upload a file to my drive as below:

media = MediaFileUpload(
    filename,
    mimetype=mimetype,
    resumable=True
)
request = service.files().create(
    media_body=media,
    body={'name': remotefilename, 'parents': [folderId]}
)

But if I upload the same file multiple times, it will generate multiple copies. Is it possible to keep the same file but keep different version? just like what the UI update version does?

1

There are 1 best solutions below

2
CMB On

Solution:

Instead of a create request, you can issue an update request to an existing file with newRevision parameter set to true to create a new revision for the same file.

For more information on how to use Files: update, you can check the official API documentation.