【发布时间】: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);
【问题讨论】:
-
你确定你的 mime 类型吗?此外,必须有一个参数来将上传的文档转换为本地 Google Drive 文件。见developers.google.com/drive/v2/reference/files/insert
-
@Alexender,你为什么要编辑所有这些问题的标题?
标签: php google-app-engine google-drive-api google-drive-realtime-api