Uploading image file to google cloud bucket

限于喜欢 提交于 2019-12-25 00:50:16

问题


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:


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.



来源:https://stackoverflow.com/questions/48558866/uploading-image-file-to-google-cloud-bucket

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