Set the If-Match HTTP header:
final Update update = mService.files().update(mDriveFile.getId(), mDriveFile, byteContent); final HttpHeaders headers = update.getRequestHeaders(); headers.setIfMatch(mDriveFile.getEtag()); update.setRequestHeaders(headers); mDriveFile = update.execute();
In case the document has changed at the same time, the update will be rejected with a response something like:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 412 Precondition Failed { "code": 412, "errors": [ { "domain": "global", "location": "If-Match", "locationType": "header", "message": "Precondition Failed", "reason": "conditionNotMet" } ], "message": "Precondition Failed" }
Please note that the ETag may change even if the content is gone .
source share