function doResumableUpload(Google_Client $client) { // Drive service $driveService = new Google_Service_Drive($client); $gs_basepath = 'gs://' . CloudStorageTools::getDefaultGoogleStorageBucketName(); $fileName = UPLOAD_FILENAME; // 82.52MB file $fileToUploadPath = $gs_basepath . "/{$fileName}"; $uploadFilesize = filesize($fileToUploadPath); $options = array('gs' => array('enable_cache' => false, 'acl' => 'public-read')); $ctx = stream_context_create($options); if (($handle = fopen($fileToUploadPath, 'r', false, $ctx)) === false) { throw new Exception('fopen failed.'); } $mimeType = CloudStorageTools::getContentType($handle); // prepare a drive file $file = new Google_Service_Drive_DriveFile(); $file->setTitle($fileName); $file->setMimeType($mimeType); $file->setFileSize($uploadFilesize); // You can also set the parent folder: // @see https://developers.google.com/drive/v2/reference/files/insert $chunkSizeBytes = 256 * 1024 * 4 * 1; // upload in multiples of 256K (1M * n) // Call the API with the media upload, defer so it doesn't immediately return. $client->setDefer(true); $request = $driveService->files->insert($file); // Create a media file upload to represent our upload process. $media = new Google_Http_MediaFileUpload($client, $request, $mimeType, null, true, $chunkSizeBytes); // set the media filesize to the actual filesize. $media->setFileSize($uploadFilesize); // Upload the various chunks. $status will be false until the process is complete. $status = false; while (!$status && !feof($handle)) { $chunk = readChunk($handle, $chunkSizeBytes); $status = $media->nextChunk($chunk); } fclose($handle); // Reset to the client to execute requests immediately in the future. $client->setDefer(false); var_dump($status); }