[英]Can't update Google Drive file
我正在尝试使用v3 Google Drive SDK将文件上传到Google云端硬盘:
$this->drive()
->files
->update(
$this->report->getId(),
$this->report, // This is a Google_Service_Drive_DriveFile instance
[
'uploadType' => 'multipart',
'data' => file_get_contents($this->getLocalReportLocation())
]
);
我收到以下例外:
调用PATCH时出错https://www.googleapis.com/upload/drive/v3/files/ABCDe4FGHvXZTKVOSkVETjktNE0?uploadType=multipart :( 403)资源正文包含不可直接写入的字段。
显然这个问题是由$this->report
引起的,我通过以下方式获得:
// Fetch the latest synchronized report
$latestReport = $this->drive()
->files
->listFiles([
'orderBy' => 'modifiedTime',
'q' => '\''.$this->userEmail.'\' in owners AND name contains \'AppName\'',
])
->getFiles()[0];
$this->report = $this->drive()
->files
->get($latestReport->id);
可能是$this->report
,它是\\Google_Service_Drive_DriveFile
一个实例,包含一些在设置并传递给update()
方法时导致问题的字段。
我能够通过将\\Google_Service_Drive_DriveFile
的新实例传递给update()
方法来解决问题,如下所示:
$this->drive()
->files
->update($this->report->getId(), (new \Google_Service_Drive_DriveFile()), [
'uploadType' => 'multipart',
'data' => file_get_contents($this->getLocalReportLocation()),
'mimeType' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.