简体   繁体   English

使用Google Drive API将照片上传到免费存储空间

[英]Upload photo to free storage with google drive api

I'm able to upload a file to google drive with that code: 我可以使用该代码将文件上传到Google驱动器:

//Insert a file
$file = new Google_Service_Drive_DriveFile();
$file->setName(uniqid().'.jpg');
$file->setDescription('A test document');
$file->setMimeType('image/jpeg');

$data = file_get_contents('a.jpg');

$createdFile = $service->files->create($file, array(
      'data' => $data,
      'mimeType' => 'image/jpeg',
      'uploadType' => 'multipart'
    ));

But it will be counted in the quota. 但这将计入配额中。 How to send it to free storage like google photo ? 如何将其发送到Google图片等免费存储空间?

If you want to use the Google Photos, you should use the Google Photos APIs upload media . 如果您想使用Google Photos,则应该使用Google Photos API上传媒体

Note: All media items uploaded to Google Photos through the API are stored in full resolution at original quality . 注意:通过API上传到Google相册的所有媒体项目均以完整分辨率以原始质量存储。 If your uploads exceed 25MB per user, your application should remind the user that these uploads will count towards storage in their Google Account. 如果每个用户上传的文件超过25MB,则您的应用程序应提醒用户,这些上传文件将计入其Google帐户中的存储空间。

Bytes are uploaded to Google using upload requests. 使用上传请求将字节上传到Google。 If the upload request is successful, an upload token which is in the form of a raw text string, is returned. 如果上传请求成功,则返回原始文本字符串形式的上传令牌。 To create media items, use these tokens in the batchCreate call. 要创建媒体项目,请在batchCreate调用中使用这些标记。

 // Create a new upload request // Specify the filename that will be shown to the user in Google Photos // and the path to the file that will be uploaded // When specifying a filename, include the file extension try { $uploadToken = $photosLibraryClient->upload(file_get_contents($localFilePath), $filename); } catch (\\GuzzleHttp\\Exception\\GuzzleException $e) { // Handle error } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM