我正在使用谷歌驱动器sdk上传文件,而且我认为我可能会在上面创建pdf文件,所以我调整了代码。因此,在我的代码中,我生成HTML文本格式,用作在谷歌驱动器中创建PDF的内容。
这是我代码的一个片段。
$subcontent = "<h1>Hello World</h1><p>some text here</p>";
$file = new Google_DriveFile();
....
$mkFile = $this->_service->files->insert($file, array('data' => $subcontent));
$createdFile = $fileupload->nextChunk($mkFile, $subcontent); // I got error on this line
$this->_service->files->trash( $createdFile['id'] );
...
当我运行代码时,我收到了一个错误,基于我在上面代码中的注释:
Catchable fatal error: Argument 1 passed to Google_MediaFileUpload::nextChunk() must be an instance of Google_HttpRequest, array given, called in /home/site/public_html/mywp/wp-content/plugins/mycustomplugin/functions.php on line 689 and defined in /home/site/public_html/mywp/wp-content/plugins/mycustomplugin/gdwpm-api/service/Google_MediaFileUpload.php on line 212
我不知道nextChunk
中第二个参数的值应该是什么,在原始代码中是这样的:
.....
$handle = fopen($path, "rb");
while (!$status && !feof($handle)) {
$max = false;
for ($i=1; $i<=$max_retries; $i++) {
$chunked = fread($handle, $chunkSize);
if ($chunked) {
$createdFile = $fileupload->nextChunk($mkFile, $chunked);
break;
}elseif($i == $max_retries){
$max = true;
}
}
.....
我的问题是,我该如何处理这个错误?以及如何通过调整此代码在谷歌驱动器中成功创建pdf文件?因为我需要在我的帖子中链接文件的创建文件ID。
提前感谢。。。
您不应该将$mkFile传递给nextChunk。阅读文档中的可恢复上传部分。
不过,你还有更根本的问题。例如,您执行的插入调用已经设置了文件的数据。没有必要用nextChunk做任何事情,除非你正在进行可恢复的上传。按照上面文档的"Multipart File Upload"部分修复插入语句,只需删除下一行。