2
votes
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

2
Reading the comments on other answers, it appears the original problem described in your post has been resolved. Perhaps you should edit the question to add information about the further problem, including errors you see, but omitting private information like project IDs. I'm having a bit of trouble determining where you're getting stuck now.jdp

2 Answers

1
votes

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.

0
votes

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

composer require google/cloud-storage