Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google AppEngine Blobstore: Downloading a Blob by Filename in Java

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.

like image 692
Zenanon Avatar asked Dec 12 '22 14:12

Zenanon


1 Answers

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();
like image 126
systempuntoout Avatar answered Dec 15 '22 02:12

systempuntoout