ivanvermeyen/laravel-google-drive-demo

Empty file contents

Opened this issue · 0 comments

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);

    }

}