简体   繁体   English

如何按名称从BlobStore读取文件

[英]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/ 假设我有一些文件的上传表单,例如文档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 . 如果我将文件file.txt保存到blobstore,那么如果我不知道它是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. 更准确地说,我想通过以下请求获得此文件: myapp.appspot.com/getfile?file_name=file.txt file.txt ,我只想在此url上查看文件file.txt

If you use Blobstore, you have to remember a key somewhere in order to retrieve the blob. 如果使用Blobstore,则必须记住某处的密钥才能检索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. 如果使用Blobstore将文件存储在Cloud Storage中,则可以使用对象名称访问它们,该名称可以是上载文件的原始名称。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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