I am working on project using GWT Java. I uploaded excel file into blobstore in google app engine. I want to read excel file from blobstore. So I have to assign the that excel file from blobstore to 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? Any help?
Thanks in Advance
You can use the Apache POI to open the Excel File using your FileInputStream
with for example:
XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(<whatever>));
and work with the POI API to modify the Excelsheet or get the cellinfos. More information to Apache POI: click here .
Or to see a similar problem on SO: click here
The Apache POI XSSFWorkbook
accepts either a File
or an InputStream
. Assuming that you can access your Blob object via BlobstoreInputStream
instance, you can call:
// BlobKey blobKey = initialize your blob key
XSSFWorkbook wb = new XSSFWorkbook(new BlobstoreInputStream(blobKey));
You can access the Blobstore
via:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.