0

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) {
  }

}
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449

1 Answers1

1

This option may be a little simpler.

$file = $service->files->get($fileId, array('alt' => 'media'));
file_put_contents($file->name, $file->getBody());
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449