ivanvermeyen / laravel-google-drive-demo

Laravel & Google Drive Storage - Demo project with Laravel 5.4
403 stars 155 forks source link

Empty file contents #85

Open richardhedges opened 4 years ago

richardhedges commented 4 years ago

I'm having trouble retrieving the contents of a file. I've created an array of files using the following:

$service = Storage::cloud()->getAdapter()->getService();
$files = Storage::cloud()->listContents('/');

I'm then looping that array and running the following:

$export = $service->files->export($file['path'], 'text/plain');
$contents = $export->getBody();

The above returns a Guzzle stream, so if I change the $contents variable to the following to retrieve the contents, I instead see an empty string:

$contents = $export->getBody()->getContents();

I have also tried using $file['basename'] instead of $file['path'] , but I see the same results.

Full code if it's needed ``` $service = Storage::cloud()->getAdapter()->getService(); $files = Storage::cloud()->listContents('/', false); foreach ($files as $file) { if ($file['name'] == 'test') { $export = $service->files->export($file['path'], 'text/plain'); $contents = $export->getBody()->getContents(); dd($contents); } } ```