2015-07-05 112 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行。

相關問題