[英]How to get Blob Key of file to be downloaded from BlobStore in Java?
[英]How to get uploaded excel file from blobstore and how to assign that file to FileInputStream
我正在使用GWT Java進行項目。 我將Excel文件上傳到了Google App Engine中的Blobstore中。 我想從blobstore讀取Excel文件。 因此,我必須將excel文件從blobstore分配給FileInputStream。
例:
FileInputStream file = new FileInpuStream("what is path shall i provide here")
將Blobstore中的excel文件分配給FileInputStream的可能方法是什么? 有什么幫助嗎?
提前致謝
Apache POI XSSFWorkbook
接受File
或InputStream
。 假設您可以通過BlobstoreInputStream
實例訪問Blob對象,則可以調用:
// BlobKey blobKey = initialize your blob key
XSSFWorkbook wb = new XSSFWorkbook(new BlobstoreInputStream(blobKey));
您可以通過以下方式訪問Blobstore
:
public class Upload extends HttpServlet {
private BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
@Override
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
Map<String, List<BlobKey>> blobs = blobstoreService.getUploads(req);
List<BlobKey> blobKeys = blobs.get("myFile");
if (blobKeys != null && !blobKeys.isEmpty()) {
XSSFWorkbook wb = new XSSFWorkbook(new BlobstoreInputStream(blobKeys.get(0)));
}
}
}
進一步閱讀: Blobstore Java API概述
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.