【问题标题】:How to set Google application credentials in Rails如何在 Rails 中设置 Google 应用程序凭据
【发布时间】:2019-12-24 18:48:02
【问题描述】:

我正在关注 Google 的“Using the client library”并尝试使用 Google Cloud 平台将图像上传到我在 Google 上创建的存储桶。我还创建了一个服务并将 JSON 文件本地下载到我的项目中。

JSON 直接位于我的config/ 文件夹中。

我还为 Google 添加了所需的 gem,并且正在使用 Figaro gem 来处理环境变量。

我不明白如何将环境变量的值设置为指向包含我的服务凭据的 JSON 文件。

这是我在控制器的 POST 操作中的代码:

storage = Google::Cloud::Storage.new project_id: '******'
bucket  = storage.bucket '******'
bucket.create_file allowed_params["image"], storage_file_path

这就是我尝试在 application.yml 文件中设置 GOOGLE_APPLICATION_CREDENTIALS 的方式:

GOOGLE_APPLICATION_CREDENTIALS: *********-3d373986410c6.json

文件application.yml 和我的*********-3d373986410c6.json 位于同一文件夹/路径中。

我得到的错误是:

Could not load the default credentials. Browse to https://developers.google.com/accounts/docs/application-default-credentials for more information

我错过了什么?

【问题讨论】:

  • 环境变量GOOGLE_APPLICATION_CREDENTIALS的值是多少?在代码中添加调试行并验证值。
  • 它是 nil 但在 application.yml 中设置
  • 从代码内部检查时的值是多少?错误消息表明您没有正确设置值。
  • 这篇文章解决了我的问题medium.com/@pjbelo/…
  • 您可以添加评论作为答案吗?

标签: ruby-on-rails ruby google-cloud-platform


【解决方案1】:

@webbie 自己解决了这个问题,从问题 cmets 中可以看出。 将评论添加为社区 Wiki 答案以提高解决方案的可见性:

“这篇文章解决了问题https://medium.com/@pjbelo/setting-up-rails-5-2-active-storage-using-google-cloud-storage-and-heroku-23df91e830f8

【讨论】:

  • 另外,请将解决方案添加到您的答案中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-26
  • 2020-12-12
  • 2022-11-10
  • 1970-01-01
  • 2019-04-05
相关资源
最近更新 更多