Reputation: 1
I am facing issue "Call to a member function getBody() on string" I am using following code
public function downloadFile($fileId , $name)
{
try
{
$content = $this->service->files->get($fileId, array("alt" => "media"));
$outHandle = fopen(APPPATH ."Downloads". "/" . $name , "w+");
while (!$content->getBody()->eof()) {
fwrite($outHandle, $content->getBody()->read(1024));
}
fclose($outHandle);
return $outHandle;
} catch (\Exception $e) {
}
}
Upvotes: 0
Views: 265
Reputation: 116948
This option may be a little simpler.
$file = $service->files->get($fileId, array('alt' => 'media'));
file_put_contents($file->name, $file->getBody());
Upvotes: 1