Page 1 of 1

mime-type of docx generated by docx4j

PostPosted: Fri Jun 07, 2024 3:28 am
by Jdub
Hi,
I use docx4j 8.3.10
When I check a docx file generated by docx4j with "file --mime-type" command, I get "application/octet-stream"
But when I check a file generated by word, I get "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
Is there a way to change the mime type generated by docx4j ?
(my files are not allowed by a API due to this mime type)

Re: mime-type of docx generated by docx4j

PostPosted: Sat Jun 08, 2024 12:10 pm
by jason
I just ran the sample OpenAndSaveRoundTripTest, and then on its output:

Code: Select all
$ file --mime-type OUT_OpenAndSaveRoundTripTest.docx                                     
OUT_OpenAndSaveRoundTripTest.docx: application/vnd.openxmlformats-officedocument.wordprocessingml.document


So that looks right.

This was on Manjaro Linux: 6.1.85-1-MANJARO

Where to go from here?
- feel free to send me your generated docx file so we can see what file reports on it here
- what platform are you running file on?
- look at the source code for your file command to see what it is doing?
- possibly the version of commons-compress used by docx4j matters? (here my sample docx file was created using 1.26.1)

Re: mime-type of docx generated by docx4j

PostPosted: Mon Jun 10, 2024 6:27 pm
by Jdub
Hi Jason
I understood my issue : my code use existing docx files to generate new docx files. These existing docx files have a "application/octet-stream" mime-type (I don't know why).
Just use wordMLPackage.save() keep the wrong mime-type, but use the sample MergeDocx generate a docx file with the right mime-type.
So problem fixed for me
Thanks

Re: mime-type of docx generated by docx4j

PostPosted: Tue Jun 11, 2024 8:28 am
by jason
Seems like there still might be something worth investigating here.
What happens if you run an existing file through https://github.com/plutext/docx4j/blob/ ... ingle.java

If that results in a docx with the wrong mime type, it should be free of any meaningful info, so you could post it here.