I am trying to upload a large power point file to google drive using the PHP API. When I use the code below, the file uploads, but appears to be garbage when I open it through the google drive interface. Anybody know what I need to change?

    $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);
有帮助吗?

解决方案

Where you have text/plain (mime type), you should probably change it to tell Google Drive this is an MS PowerPoint, so try application/vnd.ms-powerpoint or application/vnd.openxmlformats-officedocument.presentationml.presentation and see if you get better results.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top