Mirko Pelgrom
Mirko Pelgrom

Reputation: 91

INVALID_BLOB_KEY on retrieving image from Google Cloud storage using java

I'm trying to use Google Cloud storage to store images that I'll be using in jsp files. I've created the bucket, uploaded an image (for testing purposes) and try to retrieve a Url to it from a java class. I keep getting the error message

    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)

The Bucket I created

The Bucket I created

The code I use to retrieve the Url (BUCKETNAME is a static string with the name of the bucket)

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;
}

I've tried to make the image public, but that didn't help. I've looked through various answers here, but I'm a bit lost. Any help would be appreciated

Upvotes: 4

Views: 507

Answers (1)

Kanishk Gupta
Kanishk Gupta

Reputation: 379

I also faced the same issue. For future people, make sure you have made the bucket public. From the same method you can also generate thumbnails and secured urls to your images

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;
}

Upvotes: 1

Related Questions