2

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!

Nico Nisaw
  • 57
  • 1
  • 6
  • What are the roles of the current credential? Do you have the email of the current credential? Can you provide more detail on the underlying identity? – guillaume blaquiere Jun 04 '21 at 07:21

1 Answers1

3

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.

Storage Object Admin permission analysis

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

Eddy Goh
  • 256
  • 5
  • 11