将图像文件上传到Google云存储桶 [英] Uploading image file to google cloud bucket
本文介绍了将图像文件上传到Google云存储桶的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
现在,我想将图像文件上传到gcp存储桶,因为我正在使用以下代码:
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'
]);
其中$params
变量包含此内容
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
)
)
推荐答案
除非您使用应用程序默认凭据,您必须设置GOOGLE_APPLICATION_CREDENTIALS
环境变量以指向服务帐户密钥文件.请参见此处的示例.
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.
这篇关于将图像文件上传到Google云存储桶的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文