[英]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.