簡體   English   中英

使用Google Drive API將照片上傳到免費存儲空間

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

我可以使用該代碼將文件上傳到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'
    ));

但這將計入配額中。 如何將其發送到Google圖片等免費存儲空間?

如果您想使用Google Photos,則應該使用Google Photos API上傳媒體

注意:通過API上傳到Google相冊的所有媒體項目均以完整分辨率以原始質量存儲。 如果每個用戶上傳的文件超過25MB,則您的應用程序應提醒用戶,這些上傳文件將計入其Google帳戶中的存儲空間。

使用上傳請求將字節上傳到Google。 如果上傳請求成功,則返回原始文本字符串形式的上傳令牌。 要創建媒體項目,請在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