Set HTTP header in disk request

I want to detect a conflict when updating a file in Drive. For this, it seems to me that I should set the If-Match header .

I am currently updating a document in Google Drive using this one-line interface:

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

What is the easiest way to add an If-Match header to a query? File example: upgrade documentation does not talk about how to set HTTP headers.

+1
source share
1 answer

You can get the headers from the Update object, add your own and return them 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(); 
0
source

Source: https://habr.com/ru/post/1496546/


All Articles