2015-07-05 70 views
1

我使用谷歌驱动器sdk上传文件,我想我可以创建PDF文件 - 所以我调整了代码。因此,在我的代码中,我生成HTML文本格式以用作要在Google Drive中创建的PDF的内容。使用谷歌驱动器创建PDF文件的错误sdk

这是我的代码片段。

$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。

在此先感谢...

回答

0

您不应该将$ mkFile传递给nextChunk。请阅读resumable uploads section in the documentation

你有更多的根本问题比。例如,您所做的插入调用已经设置了该文件的数据。除非您正在进行可恢复的上传,否则无需对nextChunk执行任何操作。按照上述文档的“多部分文件上传”部分修复您的插入语句,并删除nextChunk行。

相关问题