Как загрузить большой файл PowerPoint на диск Google?
Я пытаюсь загрузить большой файл Power Point на Google Drive, используя PHP API. Когда я использую приведенный ниже код, файл загружается, но при открытии его через интерфейс Google Drive появляется мусор. Кто-нибудь знает, что мне нужно изменить?
$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 ответ
Решение
Где у вас есть text/plain
(MIME-тип), вы, вероятно, должны изменить его, чтобы сообщить Google Drive, что это MS PowerPoint, поэтому попробуйте application/vnd.ms-powerpoint
или же application/vnd.openxmlformats-officedocument.presentationml.presentation
и посмотреть, если вы получите лучшие результаты.