Results 1 to 4 of 4
- 04-30-2014, 06:29 PM #1
Member
- Join Date
- Apr 2014
- Posts
- 2
- Rep Power
- 0
Your InputStream was neither an OLE2 stream, nor an OOXML stream
I am using Apache Commons to upload a .docx . While uploading, I also want to extract text by using Apache POI libraries.
If I pass the inputstream returned from item.openStream(); from ServletFileUpload to POI API,I get the exception:java.lang.IllegalArgumentException: Your InputStream was neither an OLE2 stream, nor an OOXM
public static String docx2text(InputStream is) throws Exception {
return ExtractorFactory.createExtractor(is).getText();
}
my application server does not allow me to write to file, so I cannot use FileInputStream.
how do I handle this? I am uploading valid .docx file.There are no issues with uploading file.
-regards
MaLast edited by manjesh; 04-30-2014 at 06:35 PM.
- 05-01-2014, 10:42 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
Re: Your InputStream was neither an OLE2 stream, nor an OOXML stream
Can you show the code that calls this, presumably the one that gets hold of the input stream?
Please do not ask for code as refusal often offends.
** This space for rent **
- 05-01-2014, 02:33 PM #3
Member
- Join Date
- Apr 2014
- Posts
- 2
- Rep Power
- 0
Re: Your InputStream was neither an OLE2 stream, nor an OOXML stream
hi, this is the servlet code . I reff apache commons file upload link http://commons.apache.org/proper/com...streaming.html
protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
RequestDispatcher rd;
try {
ServletFileUpload upload = new ServletFileUpload();
response.setContentType("text/plain");
FileItemIterator iterator = upload.getItemIterator(request);
while (iterator.hasNext()) {
FileItemStream item = iterator.next();
InputStream stream = item.openStream();
if (item.isFormField()) {
System.out.println("Got a form field: "
+ item.getFieldName());
} else {
String plainText=docx2text(stream);// throws Exception: Your InputStream was neither an OLE2 stream, nor an OOXML stream
byte data[]=IOUtils.toByteArray(stream);
//Save the data byte array to database
System.out.println("Document saved successfuly");
rd = request.getRequestDispatcher("/html/uploadhelper.jsp");
rd.forward(request, response);
}
}
} catch (Exception ex) {
ex.printStackTrace();
rd = request.getRequestDispatcher("/jsp/error/error.jsp");
rd.forward(request, response);
}
}
public static String docx2text(InputStream is) throws Exception {
return ExtractorFactory.createExtractor(is).getText();
}Last edited by manjesh; 05-01-2014 at 02:36 PM.
- 05-01-2014, 05:13 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
Re: Your InputStream was neither an OLE2 stream, nor an OOXML stream
Check the content type of the thing you think is the excel file data.
Failing that, also take a look at what is actually being sent to the server from your browser.Please do not ask for code as refusal often offends.
** This space for rent **
Similar Threads
-
Help with input stream
By Slice28 in forum New To JavaReplies: 1Last Post: 03-14-2012, 10:45 PM -
IO stream
By sadeem in forum New To JavaReplies: 4Last Post: 04-10-2011, 09:08 PM -
TCP stream cypher
By Koren3 in forum NetworkingReplies: 2Last Post: 05-20-2009, 11:08 PM -
video stream
By Alan in forum Advanced JavaReplies: 2Last Post: 05-17-2007, 09:12 AM
Bookmarks