简体   繁体   中英

Upload photo to free storage with google drive api

I'm able to upload a file to google drive with that code:

//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 ?

If you want to use the Google Photos, you should use the Google Photos APIs upload media .

Note: All media items uploaded to Google Photos through the API are stored in full resolution at original quality . If your uploads exceed 25MB per user, your application should remind the user that these uploads will count towards storage in their Google Account.

Bytes are uploaded to Google using upload requests. 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.

 // 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 } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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