Reputation: 6763
I'm trying to upload a file to Google Drive using the the v3 Google Drive SDK:
$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())
]
);
And I receive the following exception:
Error calling PATCH https://www.googleapis.com/upload/drive/v3/files/ABCDe4FGHvXZTKVOSkVETjktNE0?uploadType=multipart: (403) The resource body includes fields which are not directly writable.
Upvotes: 3
Views: 611
Reputation: 6763
Apparently the issue is caused by $this->report
which I obtain in the following way:
// 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);
Probably $this->report
, which is an instance of \Google_Service_Drive_DriveFile
, contains some fields that are causing issues when set and passed to the update()
method.
I was able to solve the problem by passing a new instance of \Google_Service_Drive_DriveFile
to the update()
method like this:
$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'
]);
Upvotes: 2