代码之家  ›  专栏  ›  技术社区  ›  porton

编辑Google存储对象元数据需要哪些权限?

  •  2
  • porton  · 技术社区  · 7 年前

    我有以下Perl代码:

      $response = $process->request('PATCH',
                                    "https://www.googleapis.com/storage/v1/b/$Bucket/o/$EscapedName",
                                    '{"content-type": "image/jpeg"}',
    #                                 '{"metadata": {"Content-Type": "image/jpeg"}}',
                                    {'Content-Type' => 'application/json'});
      unless ($response->is_success) {
        print "Content-Type: text/plain\n\n";
        print $response->status_line . "\n" . $response->decoded_content . "\n" ;
        exit;
      }
    

    它产生

    403 Forbidden
    {
     "error": {
      "errors": [
       {
        "domain": "global",
        "reason": "insufficientPermissions",
        "message": "Insufficient Permission"
       }
      ],
      "code": 403,
      "message": "Insufficient Permission"
     }
    }
    

    • 存储管理员
    • 存储对象查看器

    为我的用户启用。

    为什么不起作用?

    简单地上传对象确实有效,但我无法设置此元数据。

    2 回复  |  直到 7 年前
        1
  •  4
  •   Dan Cornilescu    7 年前

    要更新对象元数据,需要 storage.objects.update 许可。从 Cloud Storage IAM Permissions :

    对象权限

    ...

    storage.objects.update    Update object metadata, excluding ACLs.
    

    但两者都有 roles/storage.objectAdmin roles/storage.admin 角色(假设你所列的角色就是这个意思) 应该 已经包括了这个许可,所以可能还有别的事情在起作用。从 Standard roles :

    roles/storage.objectAdmin  Full control over objects, including listing,    storage.objects.*
                               creating, viewing, and deleting objects.
                               Does not grant permission to read or edit 
                               bucket metadata.
    roles/storage.admin        Full control of buckets and objects.             storage.buckets.*
                               When applied to an individual bucket, control    storage.objects.*
                               only to the specified bucket and objects within
                               the bucket.
    
        2
  •  3
  •   coryan    7 年前

    对象资源中属性的名称为 contentType ,你路过 content-type :

    https://cloud.google.com/storage/docs/json_api/v1/objects