Results 1 to 4 of 4
  1. #1
    manjesh is offline Member
    Join Date
    Apr 2014
    Posts
    2
    Rep Power
    0

    Default 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
    Ma
    Last edited by manjesh; 04-30-2014 at 06:35 PM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,184
    Rep Power
    20

    Default 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 **

  3. #3
    manjesh is offline Member
    Join Date
    Apr 2014
    Posts
    2
    Rep Power
    0

    Default 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.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,184
    Rep Power
    20

    Default 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

  1. Help with input stream
    By Slice28 in forum New To Java
    Replies: 1
    Last Post: 03-14-2012, 10:45 PM
  2. IO stream
    By sadeem in forum New To Java
    Replies: 4
    Last Post: 04-10-2011, 09:08 PM
  3. TCP stream cypher
    By Koren3 in forum Networking
    Replies: 2
    Last Post: 05-20-2009, 11:08 PM
  4. video stream
    By Alan in forum Advanced Java
    Replies: 2
    Last Post: 05-17-2007, 09:12 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •