首页 > 解决方案 > 没有 storage.buckets.list 访问 Google Cloud 项目的权限?

问题描述

我编写了一个 Ruby 脚本,它将音频文件上传到 Google Cloud Storage。

def upload_to_Google_cloud(audio_file)

    project_id = "<project_id>"
    key_file = "<json_file>"

    storage = Google::Cloud::Storage.new project: project_id, keyfile: key_file

    bucket_name = storage.buckets.first.name 
    puts bucket_name
      
    bucket = storage.bucket bucket_name

    local_file_path = "/path/#{audio_file}"

    file = bucket.create_file local_file_path, "#{audio_file}.flac"
    return "Uploaded #{file.name}"
end

但是,每次我运行命令 -> ruby​​ video_dictation.rb 时,它都会返回一个错误,即xxxxxxxxx 没有 storage.buckets.list 访问 Google Cloud 项目的权限。(谷歌::云::PermissionDeniedError)

任何帮助,建议?谢谢!

标签: ruby-on-railsrubygoogle-cloud-platformgoogle-speech-to-text-api

解决方案


应该是权限问题。

  1. 尝试创建一个服务帐户。它看起来像这样“my-storage-bucket@yourprojectname.iam.gserviceaccount.com”
  2. 转到 IAM 和管理 -> 权限
  3. 为该服务帐户分配“存储对象管理员”角色。
  4. 再次尝试您的代码。如果有效,请根据您的需要将您的权限范围缩小到以下列表。

存储对象管理员权限分析

5. 请记住下载该特定服务帐户的 json 密钥文件。


推荐阅读