在没有完全访问权限的情

时间:2014-07-13 01:27:00

标签: google-cloud-storage

使用具有读/写(但不是完全)访问权限的OAuth2身份验证令牌时,有没有办法更新Google Storage中对象的元数据?

我天真的尝试(带有x-goog-copy-source的HTTP PUT设置为同一个对象,和 x-goog-metadata-directive: REPLACE)因AccessDenied错误而失败。 gsutil似乎也有同样的问题:

$ gsutil config -r -w 
[...]
$ echo hello > foo.txt
$ gsutil -h "x-goog-meta-foo: bar" cp foo.txt gs://nikratio-test/
Copying file://foo.txt [Content-Type=text/plain]...
Uploading   gs://nikratio-test/foo.txt:                          0 B/6 B    
$ gsutil stat gs://nikratio-test/foo.txt
gs://nikratio-test/foo.txt:
    Creation time:      Sun, 09 Nov 2014 22:34:22 GMT
    Content-Language:   en
    Content-Length:     6
    Content-Type:       text/plain
    Metadata:
        foo:         bar
    Hash (crc32c):      NT3Yvg==
    Hash (md5):     sZRqySSS0jR8YjW00mERhA==
    ETag:           CID8ka7K7sECEAE=
    Generation:     1415572462272000
    Metageneration:     1
$ gsutil setmeta -h "x-goog-meta-foo: com" gs://nikratio-test/foo.txt
Setting metadata on gs://nikratio-test/foo.txt...
AccessDeniedException: 403 Forbidden

我认为这是因为setmeta操作还允许我更改对象的ACL。 但是,在我看来,如果我能够使用相同的授权删除对象并使用不同的元数据重新上传它,那么确实应该有一种方法来改变元数据。

1 个答案:

答案 0 :(得分:2)

设置元数据适用于OAuth2。我建议运行这个gsutil命令,并将它生成的协议输出与你正在做的事情进行比较:

gsutil -o GSUtil:prefer_api = xml -d setmeta -h x-goog-meta-data-00:gAJ9cQBYBQAAAGFwcGxlcQFYCAAAAHBvdGF0b2VzcQJzLg gs:// your-bucket / your-object