简体   繁体   中英

How to read file from BlobStore by name

Suppose I have some uploading form for files like the one in documentation https://cloud.google.com/appengine/docs/java/blobstore/

If I saved file file.txt to the blobstore, how can I get it from it if I dont know it's BlobKey . More precisely, I want to get this file with a request like this: myapp.appspot.com/getfile?file_name=file.txt and I just want to see file file.txt on this url.

If you use Blobstore, you have to remember a key somewhere in order to retrieve the blob.

If you use Blobstore to store files in Cloud Storage, then you can access them using an object name,which can be an original name of an uploaded file.

If your file is public, you can access it directly:

https://storage.googleapis.com/" + bucket + "/" + objectName

If you want to read it first in your app, and then return to a client, then you can use:

String filename = "/gs/" + bucket + "/" + objectName;
BlobstoreService blobService = BlobstoreServiceFactory.getBlobstoreService();
blobService.serve(blobService.createGsBlobKey(filename), response);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM