Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

docx won't open

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need help.

We have a database full of old resumes that are now necessary to access. They are saved in different formats, html, txt, doc, docx. I am using this code to open them.


Every format opens successfully, except docx. In Firefox, I get errors that the xml is corrupted, but if I just keep clicking through the errors, the resume will open in Word. In IE, I get a window that says do you want to open or save this file-it knows the file type is MSWord. I click OK and it doesn't do anything. If I save it to my computer, then click open, I have to find Word in the list of applications to open it. Then I get the same errors that Firefox gives, errors with the contents, click through the errors, it opens. I have asked at least 10 people to try this on their machines and everyone of us gets the same result. I have a newer XP with MS Office 2007. Others with Windows7 also gets the same result. This happens across the board on docx - there are hundreds of them in the database, so it's not just one corrupted file.

Any ideas?

 
Ranch Hand
Posts: 344
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you try the following content type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
Edit: oops... seems like you did... is this content type set correctly for the docx files?
How about application/octet-stream?
 
Jan Piper
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, Bear, Thank you!
Koen, that is exactly the code that I used and it does not work.
 
Koen Aerts
Ranch Hand
Posts: 344
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jan Piper wrote:Yes, Bear, Thank you!
Koen, that is exactly the code that I used and it does not work.


What about the more generic application/octet-stream?
 
Koen Aerts
Ranch Hand
Posts: 344
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, are the file extensions all lower case? Because .DOCX won't match your condition, but .docx would.
 
Jan Piper
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using octet-stream, I have to save it. Then choose Word, then the same errors. Yes, the ext is .docx, not .DOCX.
 
Marshal
Posts: 27374
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jan Piper wrote: I am using this code to open them.



But that code doesn't "open" anything. I realize that people use the word "open" for all kinds of vaguely-defined processes, but that code just sets the content-type of the HTTP response and does absolutely nothing with any documents at all.

You already seem to be considering the idea that the documents are being corrupted by something in the process which sends them from the browser to the database. You should continue looking at that idea, since that is most likely the problem.

You've already confirmed that it makes no difference what MIME type you use, so that's just a red herring now. It's time to look at the code which transfers the data from the database to the browser. The other possibility is that the data was corrupted by the process of putting it into the database.
 
Jan Piper
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am converting the data to a string and then opening by PrintStream.

I just find it very strange that the only data corrupted was docx. I spent the evening looking for other solutions and all I can find are other people with the same problem, but no solutions.
 
Sheriff
Posts: 22684
128
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you actually saying you've turned binary data into a String? It then surprises me that you haven't run into problems before. Binary data can contain many bytes that have no valid char representation. Turning that data into a String can cause implicit conversions to take place, which is what will corrupt your file.

To write binary data:
1) Never use JSPs; any line break between directives will be included and can (will) cause problems.
2) Never use response.getWriter() but use response.getOutputStream()
3) Write the data as bytes (byte[]) and never as chars or Strings.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had the same problem. I found a solution: specifying the "Content-Length" header as I explain here. So, in JAVA, I just needed to add this line to make it work:



Hope it could help
 
Who knew that furniture could be so violent? Put this tiny ad out there to see what happens:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic