0

i'm trying to get a servingUrl from a file store in GCS. Here is the code to generate the BlobKey from the cloudStorage data

public BlobKey getCloudStorageBlobKey(String bucket_name, String object_name)
{       
    bucket_name = StringUtils.strip(bucket_name, "/");
    object_name = StringUtils.strip(object_name, "/");

    GcsFilename gcs_file = new GcsFilename(bucket_name, object_name);
    String cloudStorageURL = "/gs/" + gcs_file.getBucketName() + "/" + gcs_file.getObjectName();

    BlobstoreService bs = BlobstoreServiceFactory.getBlobstoreService();
    BlobKey bk = bs.createGsBlobKey(cloudStorageURL);
    return bk;
}

And here the code to get the servingURL

public String getThumbUrl(BlobKey blobkey)
{       
    ServingUrlOptions options = ServingUrlOptions.Builder.withBlobKey(blobkey);

    try
    {
        return ImagesServiceFactory.getImagesService().getServingUrl(options);
    }
    catch(IllegalArgumentException e)
    {
        log().severe("BlobKey " + blobkey + " not valid: " + e.getMessage());
        return null;
    }
    catch(ImagesServiceFailureException e)
    {
        log().severe("ImageService access error");
        return null;
    }
}

When i launch the code with a blobstore BlobKey i get no errors, but when i use this method with a GCS BlobKey i always get

IllegalArgumentException

Because the APIs say:

Note that once you obtain a blobKey for the GCS object, you can pass it around, serialize it, and otherwise use it interchangeably anywhere you can use a blobKey for objects stored in Blobstore. This allows for usage where an app stores some data in blobstore and some in GCS, but treats the data otherwise identically by the rest of the app. (However, BlobInfo objects are currently not available for GCS objects.)

Where am i doing wrong?

I saw this method

ServingUrlOptions options = ServingUrlOptions.Builder.withGoogleStorageFileName(googleStorageFileName)

but i can't use this because at low-level i want to use blobkey for both BlobStore/GCS.


EDIT 1: Here's the stacktrace: http://pastebin.com/index/se5DMfHF. The strange fact is that i do not get an exception message at all


EDIT2: Problem solved: analyzing the source code of the

ImagesServiceFactory.getImagesService().getServingUrl(options);

method, i found this exception thrown:

com.google.apphosting.api.ApiProxy$ApplicationException

With a quick search i found the solution: https://stackoverflow.com/a/10051350

4

0 回答 0