我正在尝试使用v3 Google Drive SDK将文件上传到Google Drive :
$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'
]);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句