1

我想在将文件更新到驱动器时​​检测到冲突。要做到这一点,it seems I have to set the If-Match header在驱动器请求中设置HTTP标头

目前,我与这一个班轮更新文档到谷歌驱动器:

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

什么是添加If-Match头在请求中最简单的方法是什么? Example in Files: update documentation不会告诉如何设置HTTP标头。

回答

0

您可以从Update对象获得的标题,添加自己,并把他们带回执行HTTP请求之前:

final Update update = mService.files().update(mDriveFile.getId(), mDriveFile, byteContent); 
final HttpHeaders headers = update.getRequestHeaders(); 
headers.setIfMatch("TheETagStoredFromDownload"); 
update.setRequestHeaders(headers); 
mDriveFile = update.execute();