【问题标题】:How do I upload a large powerpoint file to google drive?如何将大型 powerpoint 文件上传到谷歌驱动器?
【发布时间】:2014-05-12 12:10:24
【问题描述】:

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

    $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);

【问题讨论】:

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


【解决方案1】:

如果您有 text/plain(mime 类型),您可能应该将其更改为告诉 Google Drive 这是一个 MS PowerPoint,因此请尝试使用 application/vnd.ms-powerpointapplication/vnd.openxmlformats-officedocument.presentationml.presentation 看看是否能获得更好的结果。

【讨论】:

  • 谢谢 Dan,我已经尝试了很多选项,并且可以跨 application/vnd.openxmlformats-officedocument.presentationml.presentation 并且它有效。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-10
相关资源
最近更新 更多