View Full Version : epubcheck error: mimetype entry missing or not the first in archive


rjnagle
10-10-2009, 04:31 AM
I am rolling my own epub files, and I'm getting an error on epubcheck.


mimetype entry missing or not the first in archive

A valid epub file must contain an uncompressed file named mimetype as a first entry in the zip archive. That file must contain epub mime type (application/epub+zip).

That's the only error message I get. Everything else validates through epubcheck. Frankly, this is driving me crazy!


my .epub file has this structure

myfile.epub
OEBPS/
images
index.html
content.opf
chapter1.html
etc....
META-INF/
container.xml
mimetype (this is a file and exists at root of the epub directory.)

the mimetype file has no file extension and only one line:

"application/epub+zip."

I am generating most of my files from docbook, but i just used the same mimetype file from other valid epub file, with identical results.

As I said, everything else is right. Is there something special I need to do about the way I zip up these directories, or is conceivably a whitespace issue? How fussy is the validator about the substance of the mimetype file?

Thanks for your help.

rj

Jellby
10-10-2009, 06:39 AM
As the error says, the mimetype file has to be the first file in the zip, and must be stored without compression.

What I do (on linux) is create the zip/epub file in two steps. First create the zip only with mimetype, without compression:

zip -0 file.epub mimetype

Then add the rest of the files with maximum compression:

zip -9 -r file.epub META-INF OEBPS

You can probably do the same with Winzip or similar.

rjnagle
10-10-2009, 11:18 AM
sorry to be such a windows wimp, but is there a windows way to do this?

I'm using a gui tool.

hopefully i won't need to install cygwin?

On linux, it looks so easy (sigh).

Using izarcc, I was able to eliminate the previous error only to see that I've created another error which prevents epubcheck from working.

epubcheck says; ERROR: first.epub: META-INF/container.xml is missing

calibre ebook viewer says:

---------------------------
ERROR: Could not open ebook
---------------------------
File name in directory "META-INF\container.xml" and header "META-INF/container.xml" differ.

this sounds like a zipping problem.

There looks like there's an izarcc command line utility. Other ideas?

Jellby
10-10-2009, 02:12 PM
I don't have Windows to try, but I'd say you can do something similar with Winzip:

1- Create a .zip file only with mimetype, and set it to no compression.
2- Add the rest of the files with maximum (or whatever) compression.

rjnagle
10-10-2009, 02:22 PM
yes, I tried doing what you suggested with izarc. same original problem.

Ok, I downloaded cygwin, check.

I ran the exact commands mentioned above. Epubcheck gives me this message message and no other errors:

mimetype contains wrong type (application/epub+zip expected)

Things open up in calibre and Adobe DE ok. Could this be a problem with epubcheck?

Robert Admin@kunderavista /cygdrive/i/My Documents/xml/rj3
$ zip -0 cyg2.epub mimetype
adding: mimetype (stored 0%)

Robert Admin@kunderavista /cygdrive/i/My Documents/xml/rj3
$ zip -9 -r cyg2.epub META-INF OEBPS
adding: META-INF/ (stored 0%)
adding: META-INF/container.xml (deflated 30%)
adding: OEBPS/ (stored 0%)
adding: OEBPS/bk01-toc.html (deflated 65%)
adding: OEBPS/content.opf (deflated 75%)
adding: OEBPS/cover.html (deflated 34%)
adding: OEBPS/er001.html (deflated 59%)
adding: OEBPS/er007.html (deflated 45%)
adding: OEBPS/er009.html (deflated 41%)
adding: OEBPS/es001.html (deflated 53%)
adding: OEBPS/first.css (deflated 6%)
adding: OEBPS/first.zip (deflated 64%)
adding: OEBPS/images/ (stored 0%)
adding: OEBPS/images/cover.jpg (deflated 0%)
adding: OEBPS/in001.html (deflated 53%)
adding: OEBPS/index.html (deflated 46%)
adding: OEBPS/mimetype (stored 0%)
adding: OEBPS/pr001.html (deflated 59%)
adding: OEBPS/pt01.html (deflated 41%)
adding: OEBPS/pt02.html (deflated 43%)
adding: OEBPS/pt03.html (deflated 43%)
adding: OEBPS/pt04.html (deflated 42%)
adding: OEBPS/pt05.html (deflated 41%)
adding: OEBPS/toc.ncx (deflated 82%)
adding: OEBPS/un001.html (deflated 43%)

Robert Admin@kunderavista /cygdrive/i/My Documents/xml/rj3

I'm reluctant to make this .epub public for inspection (it's for a client). But I might be able to create another project to replicate this problem.

I gotta say, this seems really weird.

rjnagle
10-10-2009, 02:39 PM
I'm not sure what I did, but when I ran this command in Cygwin shell instead, epubcheck said it worked.


$ zip -q0X rjpub.epub mimetype
$ zip -r9 rjpub.epub OEBPS META-INF


everything worked (for the time being at least). Not sure why.

Please note that I never modified the mimetype file at any point.

Peter Sorotokin
10-10-2009, 03:25 PM
yes, I tried doing what you suggested with izarc. same original problem.

Ok, I downloaded cygwin, check.

I ran the exact commands mentioned above. Epubcheck gives me this message message and no other errors:

mimetype contains wrong type (application/epub+zip expected)


make sure you mimetype file has no trailing spaces or end-of line characters in it.

Also, you can do this on Windows by creating a new "compressed folder" and drag-n-dropping your mimetype file there before everything else. It is smart enough to figure such short file does not need compression.

Jellby
10-10-2009, 03:38 PM
Well, the actual commands I use are:

zip -X0 file.epub mimetype
zip -X9Dr file.epub META-INF OEBPS

I left out the -X an -D flags because they were not meaningful for what I was trying to say, and I figured they're not actually needed (they say the zip program not to store additional file attributes and directory entries), maybe the -X flag is needed (I still don't think so)?

Other than that, and ignoring that you said you did not modify the mimetype file, I'd think, as Peter says, there's something like a spurious end-of-line or space character.

Sweetpea
10-11-2009, 04:53 AM
I use zip.exe too, with this command:

zip.exe -Xr9D book.epub mimetype *

And it works... (and I use Windows, not Linux or any other fancy OS that is so in vogue atm)

rjnagle
10-11-2009, 07:00 PM
thanks. fyi, the problem wasn't with the mimetype file (although I definitely have been bit by EOL characters before), but the way I zipped my file using izarc. i think (but could not verify) that the mimetype file was not compressed.

Thanks for your help.

DaleDe
10-13-2009, 12:46 PM
thanks. fyi, the problem wasn't with the mimetype file (although I definitely have been bit by EOL characters before), but the way I zipped my file using izarc. i think (but could not verify) that the mimetype file was not compressed.

Thanks for your help.

To verify that the mimetype is not compressed just look at the zipped file. Use more in a command line window or notepad or some other application. The whole idea is that the mimetype should show up in these kinds of applications so it can be tested without opening the file with zip.

Dale

subhash4d1
11-17-2009, 07:17 AM
First zip the mimetype file and add other files and folder in the same zip. So mimetype will be first file and ePubChecker will not give mimetype error.

Toxaris
11-18-2009, 06:38 AM
Actually, I made a small tool to create the ePub for me. Just the command, name of the ePub en the directory in which the files reside and presto.

I really hated the way Winzip for creation of the files. Actually, the tool also runs epubcheck beforehand.

GijsZePa
11-23-2009, 08:14 AM
Just registered because I'm having also the great mime-type error during validation.
I've created an C# application which creates a large Car Specifications ebook on the fly from a database source. For people who don't know C#. It's a windows application.

The whole creation of the ebook is ended by zipping the file doing the following:

Add mime-type file into a new zip file. (compression none)
close that file..

Open the same file and add the OPS and META-INF with the right files (compression Best)

The mimi-type file I'm using I took from another online epub book that's validated.
Well...this keeps on happening: ERROR: 123456.epub: mimetype contains wrong type (application/epub+zip expected)

I'm lost...nothing seems to work. Any body got a clue ?

pdurrant
11-23-2009, 08:43 AM
Post a sample ePub.


The mimi-type file I'm using I took from another online epub book that's validated.
Well...this keeps on happening: ERROR: 123456.epub: mimetype contains wrong type (application/epub+zip expected)

I'm lost...nothing seems to work. Any body got a clue ?

GijsZePa
11-23-2009, 11:22 AM
Post a sample ePub.

The real .epub is 40 + MB, this is just a subset. But the mimetype file is the problem.

Thanks !

BTW..don't shoot me because of the layout...I'm just the coder :)

Martin

Jellby
11-23-2009, 02:12 PM
The real .epub is 40 + MB, this is just a subset. But the mimetype file is the problem.

That mimetype includes a line termination (DOS style), that is an error, the mimetype file should not have any line-end, it should be just 20 bytes long (yours is 22).

pdurrant
11-23-2009, 04:31 PM
That's not his problem. If I unzip and then re-zip his file, it passes epubcheck.

The problem is the zip format.

If you look at his file with a hex editor, it should have

application/epub+zip

at bytes 0x26 to 0x3A, immediately following the mimetype filename.

In his file the mimetype filename is in the right place, but the file contents doesn't immediately follow it.

I've attached the working ePub. I don't know enough about the zip format to say exactly what's one wrong when zipping his files, but something has.

That mimetype includes a line termination (DOS style), that is an error, the mimetype file should not have any line-end, it should be just 20 bytes long (yours is 22).

GijsZePa
11-23-2009, 05:43 PM
Thanks for your investigation. It's driving me nuts.
I'm gonna post a question in the ionic zip library group (the guys who build the .net zip dll) to get some answers...

I still want to automate this task without using some thirdparty command line ziptools..

Regards !!

Martin

Jellby
11-24-2009, 05:49 AM
That's not his problem. If I unzip and then re-zip his file, it passes epubcheck.

The problem is the zip format.

Yes, you are right. Running "zip -Tv" said:

zip info: mimetype has 36 bytes of extra data
zip info: META-INF/ has 36 bytes of extra data
zip info: META-INF/container.xml has 36 bytes of extra data
zip info: OPS/ has 36 bytes of extra data
zip info: OPS/011252A.png has 36 bytes of extra data
zip info: OPS/011252B.png has 36 bytes of extra data
[...]

though the final test result is OK. Ark says the mimetype file is stored with no compression, so that part is OK too.

GijsZePa
11-24-2009, 07:30 AM
Thank you all for pointing me into the right direction:

The problem is solved with the help of the programmer of the DotNet Zip Library.

"By default, Zip entries created by DotNetZip will include extra data, for the timestamp on the file. This data will appear in the zip file immediately after the filename, and immediately before the file content. Normally this is tolerated by zip tools that read the files. In some cases it is not. To turn off the timestamp, set EmitTimesInWindowsFormatWhenSaving to false, on the ZipEntry. This would be (e.EmitTimesInWindowsFormatWhenSaving = false;)"

That will eliminate the extra data between the filename and the file content.
"

It worked and the .epub is validated OK ...

Thank you all very much for helping me solve the puzzle !

Martin

Amit Dey
12-02-2009, 11:09 AM
i have got some error container.xml missing in the meta-inf and also mimetype is miss

subhash4d1
01-22-2010, 02:14 AM
First make a zip of mimetype file then add ur all files/folders in the zip. Or provide me your sample ePub in "hello_subhash@yahoo.com". I will fix the error then you can compare zipping properties and implement.

As the error says, the mimetype file has to be the first file in the zip, and must be stored without compression.

What I do (on linux) is create the zip/epub file in two steps. First create the zip only with mimetype, without compression:

zip -0 file.epub mimetype

Then add the rest of the files with maximum compression:

zip -9 -r file.epub META-INF OEBPS

You can probably do the same with Winzip or similar.

Lucas Malor
11-16-2013, 08:16 AM
Excuse me for necromancy, I've found this article googling and it solved my problem :)

A more simple way to zip the epub is:

zip -r -X file.epub mimetype *

or better


zip -X file.epub mimetype
zip -r file.epub * -x "mimetype"