0
votes

Now, I want to upload an image file to gcp bucket, for that I am using this code:

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

Where $params variable contains this

Array
    (
    [type] => PDF
    [description] => dsds
    [book] => Array
        (
            [name] => 2017-03-23.pdf
            [type] => application/pdf
            [tmp_name] => C:\xampp\tmp\php97AA.tmp
            [error] => 0
            [size] => 45022
        )
)
1
So what is the question?Xoog
And the question is?brombeer
This I am gettingPulkit Malhotra
<b>Fatal error</b>: Uncaught exception 'Google\Cloud\Core\Exception\ServiceException' with message '{ &quot;error&quot;: { &quot;errors&quot;: [ { &quot;domain&quot;: &quot;global&quot;, &quot;reason&quot;: &quot;authError&quot;, &quot;message&quot;: &quot;Invalid Credentials&quot;, &quot;locationType&quot;: &quot;header&quot;, &quot;location&quot;: &quot;Authorization&quot; } ], &quot;code&quot;: 401, &quot;message&quot;: &quot;Invalid Credentials&quPulkit Malhotra

1 Answers

2
votes

Unless you're running on app engine using application default credentials, you'll have to set GOOGLE_APPLICATION_CREDENTIALS environment variable to point to a service account key file. See the example here.