谷歌云存储为我的公共文件返回 NoSuchKey [英] Google Cloud Storage returning NoSuchKey for my public files

查看:26
本文介绍了谷歌云存储为我的公共文件返回 NoSuchKey的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有一个公共存储桶:http://storage.googleapis.com/tripket1/

I have a public bucket here: http://storage.googleapis.com/tripket1/

并且此存储桶中的所有文件都将 ACL 设置为public-read".然而,当我尝试查看任何文件时,例如:

And all the files in this bucket have the ACL set to 'public-read'. Yet when I try to view any of the files, such as:

http://storage.googleapis.com/tripket1/2013-05-25%2019.17.32_150.jpg

它返回一个NoSuchKey"错误.

it returns a 'NoSuchKey' error.

<Error>
<Code>NoSuchKey</Code>
<Message>The specified key does not exist.</Message>
</Error>

什么可能导致这个问题?这些文件是使用 Java 的 GCS 客户端库上传的.这是从上传者那里截取的代码:

What could be causing this problem? These files were uploaded using the GCS client library for Java. Here's a code snipped from the uploader:

GcsFilename thumbGcsFilename = new GcsFilename(bucketName, thumb_filename);
GcsFileOptions options = new GcsFileOptions.Builder().mimeType("image/" + photo_extension).acl("public-read").build();
GcsOutputChannel outputChannel = gcsService.createOrReplace(thumbGcsFilename, options);
outputChannel.write(ByteBuffer.wrap(newImageData));
outputChannel.close(); 
LOGGER.info("Wrote file");

String thumb_url_str = String.format("http://storage.googleapis.com/%s/%s", bucketName, thumb_filename);
return thumb_url_str;

推荐答案

您需要对对象名称中的 % 字符进行转义.

You need to escape the % character in your object names.

例如,您有以下对象:

gs://tripket1/2013-05-25%2019.17.32_150.jpg

由于您的对象名称中有文字百分号,因此在 URL 编码时必须将其转义为 %25,以便您可以使用此 URL 访问对象:

Since you have a literal percent sign in your object's name, it must be escaped as %25 when URL encoded, so you can access the object with this URL:

http://storage.googleapis.com/tripket1/2013-05-25%252019.17.32_150.jpg

如果不转义,对象名中的 %20 在服务器端解码时会变成空格(),并且不会'找不到包含空格的对象名称.

If you don't escape it, the %20 in your object name gets turned into a space () when being decoded at the server side, and it doesn't find an object name with a space in it.

这篇关于谷歌云存储为我的公共文件返回 NoSuchKey的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆