Ruby google存储API更改公开共享

Ruby google存储API更改公开共享,ruby,google-cloud-storage,google-api-ruby-client,Ruby,Google Cloud Storage,Google Api Ruby Client,我有一个关于ruby google API的问题 我试图使用谷歌存储来承载图像。我想让每个用户都能够阅读图像。到目前为止,我可以连接到谷歌云存储并将图像上传到存储。但是,我无法通过API更改权限,我使用的代码如下: def build_client client = Google::APIClient.new() key = Google::APIClient::PKCS12.load_key('client.p12', 'notasecret') service_accoun

我有一个关于ruby google API的问题

我试图使用谷歌存储来承载图像。我想让每个用户都能够阅读图像。到目前为止,我可以连接到谷歌云存储并将图像上传到存储。但是,我无法通过API更改权限,我使用的代码如下:

 def build_client
  client = Google::APIClient.new()

  key = Google::APIClient::PKCS12.load_key('client.p12', 'notasecret')

  service_account = Google::APIClient::JWTAsserter.new(
      '553281084416-og1purkefp0md0g9n5kvlko8e74qm42v@developer.gserviceaccount.com',
      'https://www.googleapis.com/auth/devstorage.full_control',
  key)

  client.authorization = service_account.authorize
  client
end

def send_image_file(file_path, upload_file_name, client)
    storage = client.discovered_api('storage', 'v1beta2')
    media = Google::APIClient::UploadIO.new(file_path, 'image/*')
    result = client.execute(
      api_method: storage.objects.insert,
      media: media,
      parameters: {
        uploadType: 'media',
        predefinedAcl: 'publicRead',
        bucket: 'portlight_images',
        name: upload_file_name,
        projection: 'full'
      }
    )
    result
end
我使用预定义的ACL:“publicRead”来更改ACL,但它不会做任何事情。当我想使用像:{bucket}/o/{object}这样的url来访问映像时,我必须手动单击存储控制台上的按钮以使其公开共享

我想知道有没有办法通过API将链接公开给每个人。
谢谢。

您可能已经解决了这个问题,但对于其他面临同样问题的人来说: 必须在client.execute的body对象中设置acl键和值

result = client.execute(
  api_method: storage.objects.insert,
  media: media,
  parameters: {
    uploadType: 'multipart',
    bucket: 'portlight_images',
    name: upload_file_name,
    projection: 'full',
    acl: 'public-read'
  },
 :body_object => {
    'acl' => [{
        'entity' => 'allUsers',
        'role' => 'READER'  
    }],
    'bucket' => portlight_images,
    'object' => upload_file_name
  }
)

是的,这一个工作,我发现我的工作也在几天后,但你的似乎更好,谢谢!