Pulkit Malhotra
Pulkit Malhotra

Reputation: 711

Class 'Google\Cloud\Storage\StorageClient' not found

use Google\Cloud\Storage\StorageClient;
require __DIR__ . '\vendor\autoload.php';

$storage = new StorageClient();

That as my code.Here I have installed composer on windows and getting following error:-

Fatal error: Class 'Google\Cloud\StorageClient' not found in C:\xampp\htdocs\fingertips\application\controllers\teacher.php on line 214

And even after running commands with composer to use google cloud api's, then also nothing is happening.

On cmd, when I am running this, "composer require google/cloud-storage" ,I am getting this

Using version ^1.3 for google/cloud-storage ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) Nothing to install or update Generating autoload files

I have run so many commands to fix this but didnt get anything in success.Can somebody please help what went wrong

Upvotes: 3

Views: 7356

Answers (2)

Mwangi Thiga
Mwangi Thiga

Reputation: 1377

Have you installed storage client? as stated here. https://packagist.org/packages/google/cloud-storage use

composer require google/cloud-storage

Upvotes: 0

Edo Akse
Edo Akse

Reputation: 4401

In regards to your second question, you didn't include the actual error you're seeing.

I can see an issue with this code block though:

require __DIR__ . '\vendor\autoload.php';

$storage = new StorageClient();
$file = fopen($params['book']['tmp_name'], 'r');
$bucket = $storage->bucket('fingertips-books');
$object = $bucket->upload($params['book']['name'], [
    'name' => 'test.pdf'
]);

I'm missing the actual data you want to upload. The upload method needs data to upload. This should work:

require __DIR__ . '\vendor\autoload.php';

$storage = new StorageClient();
$bucket = $storage->bucket('fingertips-books');
$object = $bucket->upload(file_get_contents($params['book']['tmp_name']), [
    'name' => 'test.pdf'
]);

See the documentation for more examples of how to go about uploading a file.

Upvotes: 1

Related Questions