Set HTTP header in Drive request

2019-08-10 09:00发布

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.

1条回答
The star\"
2楼-- · 2019-08-10 09:24

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();
查看更多
登录 后发表回答