Suppose I've uploaded a bunch of files (images in this case, if it matters) to GAE's BlobStore.
Later, I want to be able to download those files from somewhere else.
I know that I can use BlobStoreService's serve method to grab a blob by BlobKey, but how do I get the blobkey associated with a given filename?
I can't seem to find any built-in functionality for this.
BlobInfo metadata that contains the filename attribute is stored in read-only __BlobInfo__
entities in the datastore.
Query query = new Query("__BlobInfo__");
query.addFilter("filename", FilterOperator.EQUAL, filename);
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
PreparedQuery pq = datastore.prepare(query);
List<Entity> entList = pq.asList(FetchOptions.Builder.withLimit(1));
String name = entList.get(0).getKey().getName();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With