Google App Engine Java - 从云存储中获取服务器URL

时间:2013-06-13 13:46:41

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

我正在尝试从GCS中的文件存储中获取serveUrl。以下是从cloudStorage数据生成BlobKey的代码

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

这里是获取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;
    }
}

当我使用blobstore BlobKey启动代码时,我没有错误,但当我使用此方法与GCS BlobKey时,我总是得到

IllegalArgumentException

因为APIs说:

  

请注意,一旦获得GCS对象的blobKey,就可以传递   它周围,序列化,以及在任何地方互换使用它   您可以将BlobKey用于存储在Blobstore中的对象。这允许   应用程序将某些数据存储在blobstore中,而某些数据存储在GCS中,但是   以其他方式完全相同地处理数据。   (但是,BlobInfo对象目前不适用于GCS   对象。)

我在哪里做错了?

我看到了这个方法

ServingUrlOptions options = ServingUrlOptions.Builder.withGoogleStorageFileName(googleStorageFileName)

但是我不能使用它,因为在低级别我想对blobStore / GCS使用blobkey。


编辑1:这是堆栈跟踪:http://pastebin.com/index/se5DMfHF。奇怪的是,我根本没有收到异常消息


EDIT2:问题解决了:分析

的源代码
ImagesServiceFactory.getImagesService().getServingUrl(options);

方法,我发现抛出了这个异常:

com.google.apphosting.api.ApiProxy$ApplicationException

通过快速搜索,我找到了解决方案:https://stackoverflow.com/a/10051350

0 个答案:

没有答案