google Drive v2 Resumable上传php api

时间:2017-12-16 17:03:08

标签: upload google-api-php-client google-api-client drive resumable

我正在阅读可恢复下载到Gdrive的说明,但没有为v2 API创建任何可行的示例  https://developers.google.com/drive/v2/reference/files/insert

如何修改此代码以便为google api ver-2客户端版本0.6.0.tar.gz

恢复上传大尺寸文件
<?
//  including api library
require_once 'src/Google_Client.php';
require_once 'src/contrib/Google_DriveService.php';
require_once 'src/io/Google_HttpRequest.php';


function insertFile($service, $title, $description, $parentId, $mimeType, 
$filename) {
$file = new Google_Service_Drive_DriveFile();
$file->setTitle($title);
$file->setDescription($description);
$file->setMimeType($mimeType);

// Set the parent folder.
if ($parentId != null) {
$parent = new Google_Service_Drive_ParentReference();
$parent->setId($parentId);
$file->setParents(array($parent));
  }

try {
$data = file_get_contents($filename);

$createdFile = $service->files->insert($file, array(
'data' => $data,
'mimeType' => $mimeType,
));

 // Uncomment the following line to print the File ID
 // print 'File ID: %s' % $createdFile->getId();

  return $createdFile;
  } catch (Exception $e) {
    print "An error occurred: " . $e->getMessage();
  }
}

?>

0 个答案:

没有答案