代码之家  ›  专栏  ›  技术社区  ›  Entretoize

使用google drive api将照片上传到免费存储区

  •  0
  • Entretoize  · 技术社区  · 6 年前

    //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'
        ));
    

    但它将被计入配额。如何将其发送到免费存储,如谷歌照片?

    1 回复  |  直到 6 年前
        1
  •  0
  •   abielita    6 年前

    如果你想使用谷歌照片,你应该使用 Google Photos APIs upload media .

    注: 通过API上传到Google照片的所有媒体项都以完全分辨率存储在 original quality . 如果你的上传超过每个用户25MB,你的应用程序应该提醒用户,这些上传将计入他们谷歌账户的存储空间。

    字节通过上传请求上传到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
    }
    
    推荐文章