google-app-engine - Google Cloud Storage 返回我的公共(public)文件的 NoSuchKey

标签 google-app-engine google-cloud-storage

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

此存储桶中的所有文件的 ACL 都设置为“公共(public)读取”。然而,当我尝试查看任何文件时,例如:

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

它返回“NoSuchKey”错误。

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

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

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;

最佳答案

您需要转义对象名称中的 % 字符。

例如,您有以下对象:

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

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

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

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

关于google-app-engine - Google Cloud Storage 返回我的公共(public)文件的 NoSuchKey,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18845762/

相关文章:

java - Spring:根据配置文件注入(inject)不同的属性文件

android - 如何从 Google Code 下载 Google Cloud Messaging (GCM)?

php - GSUTIL cp 文件从服务器到存储桶并公开文件

node.js - Google App Engine 中的文件在哪里下载?

apache-spark - 从谷歌存储 gs ://filesystem from local spark instance 读取

google-app-engine - mvn 应用程序引擎 :deploy system property for configuration

java - Google Cloud Endpoints 框架 - EndpointServlet ClassNotFoundException

python - 从 GCS 获取大量 csv 文件到 BQ

java - HTTP 500 网站无法显示页面

google-cloud-platform - 将图像数据 (tfrecords) 从 GCS 提供给模型的最佳方式是什么?