PepeHands
PepeHands

Reputation: 1406

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.

Upvotes: 1

Views: 468

Answers (1)

Andrei Volgin
Andrei Volgin

Reputation: 41089

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);

Upvotes: 1

Related Questions