【问题标题】:Upload photo to free storage with google drive api使用 google drive api 将照片上传到免费存储
【发布时间】:2018-12-01 08:30:56
【问题描述】:

我可以使用该代码将文件上传到谷歌驱动器:

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

但它会被计入配额。如何将其发送到像谷歌照片这样的免费存储空间?

【问题讨论】:

    标签: php google-drive-api drive


    【解决方案1】:

    如果您想使用 Google 相册,您应该使用Google Photos APIs upload media

    注意:通过 API 上传到 Google 相册的所有媒体项目都以全分辨率存储在 original quality。如果您的每位用户上传的内容超过 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
    }
    

    【讨论】:

    • 那不可能?
    猜你喜欢
    • 2020-11-03
    • 1970-01-01
    • 2019-04-18
    • 2021-03-13
    • 1970-01-01
    • 2018-12-29
    • 2020-03-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多