I am using google drive sdk for uploading files and also I think i can possibly create pdf file on it – so I tweak the code. So in my code, I generate HTML text format to be used as content for the PDF to be created in google drive.
this is a snip-it of my code.
$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'] );
...
when I run the code I got an error based the comment I put in my code above:
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
I have no idea what should be the value in the 2nd parameter in nextChunk
, in the original code it goes like this:
.....
$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;
}
}
.....
my question is that, how can I deal with this error? and how can I successfully create pdf file in google drive by tweaking this code? because I need the created file ID of the file to be linked in my post.
Thanks in advance…
You shouldn’t be passing $mkFile to nextChunk. Have a read though the resumable uploads section in the documentation.
You have more fundamental issues than that though. For instance, the insert call you do already sets the data for the file. There is no need to do anything with nextChunk unless you are doing resumable uploads. Follow the “Multipart File Upload” section of the above doc to fix your insert statement and just remove the nextChunk line.