我正在使用PHP设置配置,但它似乎不起作用
我阅读了https://googleapis.github.io/google-cloud-php/#/docs/google-cloud/v0.96.0/storage/bucket中给出的文档
这是我的Laravel源代码:
use Google\Cloud\Core\ServiceBuilder;
...
$projectId = 'myProjectId';
$bucketName = 'myBucketName';
$gcloud = new ServiceBuilder([
'keyFilePath' => 'resources/google-credentials.json',
'projectId' => $projectId
]);
$storage = $gcloud->storage();
$bucket = $storage->bucket($bucketName);
//change bucket configuration
$result = $bucket->update([
'cors' => [
'maxAgeSeconds' => 3600,
'method' => [
"GET","HEAD"
],
"origin" => [
"*"
],
"responseHeader" => [
"Content-Type"
]
]
]);
//print nothing and bucket doesn't changed
dd($bucket->info()['cors']);执行此代码后,bucket CORS配置不会更改(我的老板不希望我使用gsutil shell命令来处理此问题)
发布于 2019-04-22 22:12:24
你离我很近!CORS接受一个列表,所以您只需要稍微修改一下:
$result = $bucket->update([
'cors' => [
[
'maxAgeSeconds' => 3600,
'method' => [
"GET","HEAD"
],
"origin" => [
"*"
],
"responseHeader" => [
"Content-Type"
]
]
]
]);如果有帮助,请告诉我:)。
发布于 2019-03-26 05:29:11
我唯一需要更改的是,当我用laravel配置磁盘时,在为谷歌添加磁盘时使用config/filesystems.php中的代码:
'google' => [
'driver' => 's3',
'key' => 'xxx',
'secret' => 'xxx',
'bucket' => 'qrnotesfiles',
'base_url'=>'https://storage.googleapis.com'
]下面是代码示例第一次从请求中获取文件内容:
$file = $request->file('avatar')
第二,将其保存到存储中:
Storage::disk('google')->put('avatars/' , $file);
https://stackoverflow.com/questions/55349987
复制相似问题