Search code examples
javagoogle-app-engineblobstore

How to get blob filename from BlobKey on app-engine


This is a server side question. I have a BlobKey and nothing else. How do I get the blob filename from said BlobKey? I know how to get the servingUrl as

ServingUrlOptions options = ServingUrlOptions.Builder.withBlobKey(blobKey).secureUrl(false);
String servingUrl = ImagesServiceFactory.getImagesService().getServingUrl(options);

But how do I get the filename as saved/shown in Blob Viewer as for instance image_1.png? I am using Java -- not python.


Solution

  • Use the BlobInfo class.

    BlobInfoFactory blobInfoFactory = new BlobInfoFactory();
    BlobInfo blobInfo = blobInfoFactory.loadBlobInfo(blobKey);
    String fileName = blobInfo.getFilename();