从 GoogleCloudStorage 创建 BlobstoreKey
Creating BlobstoreKey from GoogleCloudStorage
我正在为使用 GAE 的项目编写此代码。我没有使用 Blobstore,但我需要使用 servingUrl 方法。
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);
当我执行其中一个代码时,我收到了这个错误:
Exception in thread "main" com.google.apphosting.api.ApiProxy$CallNotFoundException: The API package 'blobstore' or call 'CreateEncodedGoogleStorageKey()' was not found.
有什么想法吗?
@LaiaxanIV 的解决方案作为对问题的编辑发布:
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);
我正在为使用 GAE 的项目编写此代码。我没有使用 Blobstore,但我需要使用 servingUrl 方法。
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);
当我执行其中一个代码时,我收到了这个错误:
Exception in thread "main" com.google.apphosting.api.ApiProxy$CallNotFoundException: The API package 'blobstore' or call 'CreateEncodedGoogleStorageKey()' was not found.
有什么想法吗?
@LaiaxanIV 的解决方案作为对问题的编辑发布:
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);