在谷歌 Cloud 存储中,我在一个名为images的根存储桶中有一个名为cats的存储桶 . 我使用google-api-ruby-client gem上传文件 . 我能够将文件上传到根桶“图像”,但上传到'images / cats'不起作用 . 我知道谷歌 Cloud 存储中的存储桶没有斜线的概念,所以我无法弄清楚如何指定嵌套存储桶的名称 .
result = client.execute(
api_method: api.objects.insert,
media: media,
parameters: {
uploadType: 'resumable',
bucket: 'images/cats', #This does not work !. Just images works.
name: 'kitty.jpeg',
},
body_object: {contentType: 'image/jpeg'}
)
这是错误 NoMethodError: undefined method query_values for nil:NilClass
. 如果我只使用'images'作为存储桶的值,则代码有效 .
如何使上传工作也适用于嵌套存储桶?
谢谢
1 回答
Google Cloud 端存储没有真正的目录 - 它有一个扁平的命名空间 . 您可以通过在对象名称中使用“/”字符来部分模拟目录,并在列出存储桶时使用前缀和分隔符查询 .
您看到的问题是由于存储桶名称不能包含“/”而引起的 . 请尝试使用以“cats /”开头的存储桶“images”和对象名称 .