从GoogleCloudStorage创建BlobstoreKey [英] Creating BlobstoreKey from GoogleCloudStorage
本文介绍了从GoogleCloudStorage创建BlobstoreKey的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用GAE为这个项目写这段代码。我不使用Blobstore,但我需要使用servingUrl方法。
I'm writting this code for a project using GAE. Im not using Blobstore but i need to use the servingUrl method.
GcsFilename gcsFilename = new GcsFilename(myBucket, myFileName);
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
BlobKey blobKey = blobstoreService.createGsBlobKey(
"/gs/" + gcsFilename.getBucketName() + "/" + gcsFilename.getObjectName());
ImagesService images = ImagesServiceFactory.getImagesService();
GcsFilename gcsFilename = new GcsFilename(myBucket, myFileName);
BlobstoreService blobstore = BlobstoreServiceFactory.getBlobstoreService();
BlobKey blobKey = blobstore.createGsBlobKey(key);
ServingUrlOptions opts = ServingUrlOptions.Builder.
withBlobKey(blobKey).
secureUrl(true);
images.getServingUrl(opts);
当我执行这些代码时,我得到这个错误:
When I execute one of this codes, im getting this error:
线程main中的异常com.google.apphosting.api.ApiProxy $ CallNotFoundException:未找到API程序包blobstore或调用CreateEncodedGoogleStorageKey()。 / p>
Exception in thread "main" com.google.apphosting.api.ApiProxy$CallNotFoundException: The API package 'blobstore' or call 'CreateEncodedGoogleStorageKey()' was not found.
有什么想法?
Any idea?
推荐答案
@ LaiaxanIV的解决方案发布为对该问题的编辑:
@LaiaxanIV's solution posted as an edit to the question:
解决方案我找到了:
SOLUTION I FOUND:
String key = ""; // Such as /gs/example-bucket/categories/animals.png"
ImagesService images = ImagesServiceFactory.getImagesService();
BlobstoreService blobstore = BlobstoreServiceFactory.getBlobstoreService();
BlobKey blobKey = blobstore.createGsBlobKey(key);
ServingUrlOptions opts = ServingUrlOptions.Builder.
withBlobKey(blobKey).
secureUrl(true);
return images.getServingUrl(opts);
这篇关于从GoogleCloudStorage创建BlobstoreKey的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文