1

I want to detect conflict when updating a file to Drive. To accomplish this, it seems I have to set the If-Match header.

Currently, I update the doc to Google Drive with this one-liner:

mDriveFile = mService.files().update(mDriveFile.getId(), mDriveFile, byteContent).execute();

What is the simplest way to add the If-Match header in the request? Example in Files: update documentation does not tell how to set HTTP headers.

Community
  • 1
  • 1
Juuso Ohtonen
  • 8,826
  • 9
  • 65
  • 98

1 Answers1

0

You can get the headers from Update object, add your own and put them back before executing the HTTP request:

final Update update = mService.files().update(mDriveFile.getId(), mDriveFile, byteContent);
final HttpHeaders headers = update.getRequestHeaders();
headers.setIfMatch("TheETagStoredFromDownload");
update.setRequestHeaders(headers);
mDriveFile = update.execute();
Juuso Ohtonen
  • 8,826
  • 9
  • 65
  • 98