我这里有一个公共(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/