簡體   English   中英

GAE:以編程方式訪問Blobstore內容?

[英]GAE: Access blobstore content programmatically?

我的用例:我不使用Blobstore上載和下載文件。 我使用blobstore存儲我的程序正在創建的非常大的字符串。 通過保留存儲Blob的路徑,以后我可以再次加載字符串(請參閱文檔

我的問題:是否有一種無需存儲路徑即可更輕松地訪問Blob內容的方法? BlobstoreService僅允許我直接提供給HttpServletReponse。

您只需要存儲一個BlobKey-無需存儲路徑(文件或非文件)。

要訪問Blob的內容:

BlobstoreService blobStoreService = BlobstoreServiceFactory.getBlobstoreService();
String myString =
   new String(blobStoreService.fetchData(blobKey, 0, BlobstoreService.MAX_BLOB_FETCH_SIZE-1);

編輯:如果您有一個很長的字符串,則可以通過從循環中從blob提取數據的任何標准方式,將字節數組讀取為字符串。

我猜想當您說“堅持斑點的存儲路徑”時,您是說BlobKey嗎?

FileService允許您直接訪問Blob數據:

// Get a file service
FileService fileService = FileServiceFactory.getFileService();

// Get a file backed by blob
AppEngineFile file = fileService.getBlobFile(blobKey)

// get a read channel
FileReadChannel readChannel = fileService.openReadChannel(file, false);

// Since you store a String, I guess you want to read it a such
BufferedReader reader = new BufferedReader(Channels.newReader(readChannel, "UTF8"));
// Do this in loop unitil all data is read
String line = reader.readLine();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM