如何将大型powerpoint文件上传到Google云端硬盘?

时间:2014-05-12 12:10:24

标签: php google-app-engine google-drive-api google-drive-realtime-api

我正在尝试使用PHP API将大型电源点文件上传到google驱动器。当我使用下面的代码时,文件上传,但当我通过谷歌驱动器界面打开它时似乎是垃圾。有人知道我需要改变什么吗?

    $file = new Google_Service_Drive_DriveFile();
    $file->title = "Big File";
    $chunkSizeBytes = 1 * 1024 * 1024;

    // Call the API with the media upload, defer so it doesn't immediately return.
    $client->setDefer(true);
    $request = $service->files->insert($file);

    // Create a media file upload to represent our upload process.   
    $media = new Google_Http_MediaFileUpload(
     $client,
     $request,
     'text/plain',
     null,
     true,
     $chunkSizeBytes
    );
   $media->setFileSize(filesize("templates/report.pptx"));

   // Upload the various chunks. $status will be false until the process is
   // complete.
   $status = false;
   $handle = fopen("templates/report.pptx", "rb");
   while (!$status && !feof($handle)) {
   $chunk = fread($handle, $chunkSizeBytes);
   $status = $media->nextChunk($chunk);
    }

   // The final value of $status will be the data from the API for the object
   // that has been uploaded.
   $result = false;
   if($status != false) {
     $result = $status;
    }

   fclose($handle);
   // Reset to the client to execute requests immediately in the future.
  $client->setDefer(false);

1 个答案:

答案 0 :(得分:2)

如果你有text/plain(mime类型),你可能应该更改它以告诉Google云端硬盘这是一个MS PowerPoint,所以试试application/vnd.ms-powerpointapplication/vnd.openxmlformats-officedocument.presentationml.presentation,看看你是否会变得更好结果