简体   繁体   English

如何从blobstore获取上传的excel文件以及如何将该文件分配给FileInputStream

[英]How to get uploaded excel file from blobstore and how to assign that file to FileInputStream

I am working on project using GWT Java. 我正在使用GWT Java进行项目。 I uploaded excel file into blobstore in google app engine. 我将Excel文件上传到了Google App Engine中的Blobstore中。 I want to read excel file from blobstore. 我想从blobstore读取Excel文件。 So I have to assign the that excel file from blobstore to FileInputStream. 因此,我必须将excel文件从blobstore分配给FileInputStream。

Example: 例:

 FileInputStream file = new FileInpuStream("what is path shall i provide here")  

What are the possible ways to assign that excel file from blobstore to FileInputStream? 将Blobstore中的excel文件分配给FileInputStream的可能方法是什么? Any help? 有什么帮助吗?

Thanks in Advance 提前致谢

You can use the Apache POI to open the Excel File using your FileInputStream with for example: 您可以使用Apache POI通过FileInputStream打开Excel文件,例如:

XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(<whatever>));

and work with the POI API to modify the Excelsheet or get the cellinfos. 并与POI API一起修改Excelsheet或获取cellinfos。 More information to Apache POI: click here . 有关Apache POI的更多信息: 单击此处

Or to see a similar problem on SO: click here 或在SO上看到类似的问题: 单击此处

The Apache POI XSSFWorkbook accepts either a File or an InputStream . Apache POI XSSFWorkbook接受FileInputStream Assuming that you can access your Blob object via BlobstoreInputStream instance, you can call: 假设您可以通过BlobstoreInputStream实例访问Blob对象,则可以调用:

 // BlobKey blobKey = initialize your blob key
 XSSFWorkbook wb = new XSSFWorkbook(new BlobstoreInputStream(blobKey));

You can access the Blobstore via: 您可以通过以下方式访问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)));
        }
    }
}

Further reading: Blobstore Java API Overview 进一步阅读: Blobstore Java API概述

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

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