Protect file content from modification

You can use the 'contentRestrictions.readOnly' field on a `file' resource to lock a file and prevent modifications to the title, uploading a new revision, and addition of comments.

Lock file content

To lock file content, use the files.update method with the contentRestrictions.readOnly field set to true. Add an optional reason to indicate the reason for locking the file, such as "Finalized contract." The following shows how to lock file content:

Python

service.files().update(fileId=fileId,
  body={"contentRestrictions":
      [{"readOnly": "true", "reason": "Finalized contract."}]
  })

Unlock file content

To unlock file content, use the files.update method with the contentRestrictions.readOnly field set to false. The following shows how to unlock file content:

Python

service.files().update(fileId=fileId,
  body={"contentRestrictions":
      [{"readOnly": "false"}]
  })

Check a file lock

To check a file lock, use the files.get method with the contentRestrictions returned field. The following shows how check the status of a file lock:

Python

service.files()
  .get(fileId=fileId, fields="contentRestrictions").execute()