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

走远了吗. 提交于 2019-12-11 06:46:59

问题


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


回答1:


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.




回答2:


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

composer require google/cloud-storage


来源:https://stackoverflow.com/questions/48556937/class-google-cloud-storage-storageclient-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!