php - 谷歌云存储 500 内部服务器错误
问题描述
设置控制器.php:
namespace App\Controllers;
use Google\Cloud\Storage\StorageClient;
class SettingsController extends Controller {
public function createBucket($request, $response) {
$projectId = 'myProjectId'; //here I specified my projectId
$storage = new StorageClient([
'projectId' => $projectId
]);
$bucketName = 'socnetfilestestkekdsfa213kfh34';
$bucket = $storage->createBucket($bucketName);
}
}
所以,我按照文档编写了这段代码,但我总是收到 500 Network Error。
这是我的index.php:
<?php
require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../config/db.php';
$app = new \Slim\App(['settings' => $config]);
require __DIR__ . '/../app/dependencies.php';
require __DIR__ . '/../app/routes.php';
$app->run();
这是我的项目结构:
解决方案
最后,我解决了这个问题。正如我提到require __DIR__ . '/../vendor/autoload.php';
的是正确的。就我而言, 500 Error 的原因是环境变量。对于已部署的应用程序,您应该将您的 Service Google Cloud 帐户密钥 config.json 放入您的项目中。我把我的放在一个配置文件夹中(检查我上面的项目结构)。这意味着在 Heroku 的“设置”中,我需要指定
GOOGLE_APPLICATION_CREDENTIALS: ../config/yourAppName.json
推荐阅读
- php - PHP 的“使用”关键字和自动加载
- powershell - PowerShell - 如果行包含字符串,则在开头插入一些字符
- python - Python Ctypes为数据传递指针
- html - html5游戏对象移动不起作用
- python - ValueError: int() 的无效文字,基数为 10:'abc'
- c# - Autofac - 工厂的动态实例化 (func<>)
- c - 为什么这个c程序的输出是这样的?
- angular - VSCode 无法识别 Angular Material 组件(突出显示为红色)
- regex - 使用正则表达式计算 Spark (Scala) 中的 twitter 提及次数
- node.js - node-apn :应根据通知请求或一次性创建提供程序