2012-08-29 43 views
1

有没有什么办法可以通过File对象在blobstore中引用blob?我有blob key.Now我该如何引用blob?通过File对象引用blob

// Let the blob key be 'squuheaeinlie' 
File blobReference = new File(...?....); 

我实际上是指一个XML文件,它是一个blob。我想读取和写入该XML文件。

回答

2

是的,你可以通过AppEngineFile作为文件访问blobstore blob(而不是真的File,但是关闭)。

下面是关于如何write and read blobs via this API.

编辑一个完整的例子:您可以通过加载现有的斑点斑点键:

FileService fileService = FileServiceFactory.getFileService(); 
AppEngineFile file = fileService.getBlobFile(blob-key); 
FileReadChannel channel = fileService.openReadChannel(file, false); 
// now read from channel 
+0

我看着构造_AppEngineFile_.One的文档接受blobstore的_File_路径。我如何给路径?只需将键放入构造函数中?并且您引用的示例没有显示从商店中读取文件的任何片段 –

+0

添加了如何通过blob密钥加载“AppEngineFile”的示例。 –

+0

我想在浏览器中看到从blobstore中读取的xml文件作为xml文件[我正在从通道读取ByteBuffer的数据,但是之后该怎么办?如何在商店中呈现](http://i48.tinypic.com/2v0hes0.png) –