简体   繁体   中英

Does not have storage.buckets.list access to the Google Cloud project?

I wrote a Ruby script that will upload an audio file to a 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

Though, everytime I run the command -> ruby video_dictation.rb, it returns me an error which is xxxxxxxxx does not have storage.buckets.list access to the Google Cloud project. (Google::Cloud::PermissionDeniedError) .

Any help, suggestions? Thanks!

Should be permission issue.

  1. Try to create a service account. It looks like this "my-storage-bucket@yourprojectname.iam.gserviceaccount.com"
  2. Go to IAM & Admin -> Permission
  3. Assign that service account with "Storage Object Admin" role.
  4. Try your code again. If is working, please scope down your permission to the below list based on your needs.

存储对象管理员权限分析

5. Remember to download the json key file for that particular service account.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM