문제

The example code for a resumable upload (usually used for large files) in the SDK is out of date and does not work (https://github.com/google/google-api-php-client/blob/master/examples/fileupload.php).

Specifically, the $request object that is passed when getting a new Google_Http_MediaFileUpload is of the wrong class type. Google_Http_MediaFileUpload wants an Google_HTTP_Request object, but in the example code, the thing being passed is actually (in recent releases of the SDK) a Google_Service_Drive_DriveFile.

After poking around a bit, I cannot see the obvious way to do this with the current SDK, with the same economy as the example code. (I can see the long-winded way, by creating Google_HTTP_Request objects myself according to the generic API documentation).

Does anyone have an example of working code for this? (I Googled but did not find any. The changes in the SDK appear to be in the last few weeks).

도움이 되었습니까?

해결책

I tested the latest version from Git and the example is working fine. The only "problem" is that it took a little while for the script to finish processing, even after I saw the file on Google Drive.

The $request variable is actually of the expected type Google_HTTP_Request.

$request = $service->files->insert($file);

// In the above line, $service is a `Google_Service_Drive` and 
// $service->files is `Google_Service_Drive_Files_Resource`'
// which extends `Google_Service_Resource`.
// That insert() method returns the result of a call 
// to Google_Service_Resource::call(), which
// returns a Google_HTTP_Request
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top