dongmeng0317 2017-04-06 20:05
浏览 377

将文件上传到Google云端硬盘API

Need help with the google drive API. Any help would be appreciated. An image is drawn on a canvas and saved to a folder which works but then i want to get that file from its save path and upload it to google drive. Below is my code. I don't get any errors in upload.php but cant upload to google drive so unsure where I'm going wrong.

save.php

   $data = $_POST['img'];
   $data = str_replace('data:image/png;base64,','',$data);
   $data = str_replace(' ','+',$data);

   $img = base64_decode($data);
   $path = 'images/'.uniqid().'.png';

   if(file_put_contents($path,$img))
   {
       print $path;
       require "upload.php";
   }
   else
   {
      header("HTTP 500 Internal Server Error");
   }

upload.php

$client->setClientId('');
$client->setClientSecret('');
$client>setRedirectUri('');
$client->setScopes(array('https://www.googleapis.com/auth/drive.file'));


$fileMetadata = new Google_Service_Drive_DriveFile(array(
  'name' => 'photo.png'));
  $content = file_get_contents($path);
$file = $driveService->files->create($fileMetadata, array(
  'data' => $content,
  'mimeType' => 'image/png',
  'uploadType' => 'multipart',
  'fields' => 'id'));
printf("File ID: %s
", $file->id); 
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 MATLAB动图的问题
    • ¥15 求差集那个函数有问题,有无佬可以解决
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名