Creating BlobstoreKey from GoogleCloudStorage

2019-07-09 02:07发布

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:

Exception in thread "main" com.google.apphosting.api.ApiProxy$CallNotFoundException: The API package 'blobstore' or call 'CreateEncodedGoogleStorageKey()' was not found.

Any idea?

1条回答
干净又极端
2楼-- · 2019-07-09 02:52

@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);
查看更多
登录 后发表回答