【问题标题】:INVALID_BLOB_KEY on retrieving image from Google Cloud storage using javaINVALID_BLOB_KEY 使用 java 从 Google Cloud 存储中检索图像
【发布时间】:2016-02-07 11:46:10
【问题描述】:

我正在尝试使用 Google Cloud 存储来存储我将在 jsp 文件中使用的图像。我已经创建了存储桶,上传了一张图片(用于测试目的)并尝试从 java 类中检索到它的 Url。我不断收到错误消息

    HTTP ERROR 500

Problem accessing /. Reason:

INVALID_BLOB_KEY: Could not read blob.
Caused by:

java.lang.IllegalArgumentException: INVALID_BLOB_KEY: Could not read blob.
at 
com.google.appengine.api.images.ImagesServiceImpl.getServingUrl(ImagesServiceImpl.java:282)

我创建的存储桶

我用来检索 Url 的代码(BUCKETNAME 是带有存储桶名称的静态字符串)

public static String getImageURL(String inFilename) {
    String key = "/gs/" + BUCKETNAME + "/" + inFilename;
    ImagesService imagesService = ImagesServiceFactory.getImagesService();
    ServingUrlOptions options =     ServingUrlOptions.Builder.withGoogleStorageFileName(key);
    String servingUrl = imagesService.getServingUrl(options);

    return servingUrl;
}

我已尝试将图像公开,但没有帮助。我在这里查看了各种答案,但我有点迷茫。任何帮助将不胜感激

【问题讨论】:

  • 我遇到了同样的问题。我使用 Firebase 存储来保存图像。你找到解决办法了吗?你也用过 Firebase 吗?使用 withGoogleStorageFileName() 而不是 withBlobKey() 时需要 BlobKey 似乎很奇怪。
  • 我为此使用了 Google App Engine 和 java。我正在为未来的项目寻找 Firebase。如果我查看我最终得到的代码,我会选择不同的路线: public static String getImageURL(String inFolder, String inFilename) { String servingUrl = PATHNAME + BUCKETPATH + inFolder + inFilename;返回服务网址;我还记得从 localhost 使用它时遇到了一些问题。你需要做一些设置才能让它从 localhost 工作
  • 谢谢。过了一会儿,我意识到我只是在本地运行时出现错误,所以在没有本地调试的情况下设法解决了我的问题。

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


【解决方案1】:

我也遇到了同样的问题。对于未来的人,请确保您已经制作了水桶 民众。通过同样的方法,您还可以为您的图像生成缩略图和安全 url

public static String getImageURL(String inFilename) {
    String key = "/gs/" + BUCKETNAME + "/" + inFilename;
    ImagesService imagesService = ImagesServiceFactory.getImagesService();
    ServingUrlOptions options = ServingUrlOptions.Builder  
           .withGoogleStorageFileName(key).imageSize(150).secureUrl(true);
    String servingUrl = imagesService.getServingUrl(options);

    return servingUrl;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-20
    • 2017-01-16
    • 1970-01-01
    • 2020-10-23
    • 1970-01-01
    • 2019-09-27
    • 2017-07-05
    相关资源
    最近更新 更多