Farhan Siddique
Farhan Siddique

Reputation: 1

Not able to Downloading Files using Google Drive API V3

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

Answers (1)

Linda Lawton - DaImTo
Linda Lawton - DaImTo

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

Related Questions