About EPUB e-book files
An EPUB is a ZIP archive of XHTML, CSS and images. Like OpenDocument, it starts with an uncompressed mimetype file containing application/epub+zip, so readers can identify it without unzipping. Serving it with this type lets phones offer to open it in Apple Books or another reader app.
File signature
EPUB files start with 50 4B 03 04, then "mimetypeapplication/epub+zip" from byte 30. The extension and the type a browser reports for an upload both
come from the file name, so check these bytes on the server before trusting a file.
Serve .epub with the right Content-Type
Content-Type: application/epub+zip
application/epub+zip epub;
AddType application/epub+zip .epub
@epub path *.epub
header @epub Content-Type "application/epub+zip"
curl -sI https://example.com/file.epub | grep -i '^content-type'
# Content-Type: application/epub+zip
Set the type in code
res.set('Content-Type', 'application/epub+zip');
// Or make the browser download it:
res.attachment('file.epub');
import mimetypes
mimetypes.add_type('application/epub+zip', '.epub') # if your system doesn't know it
mimetypes.guess_type('file.epub')[0] # 'application/epub+zip'
mime.AddExtensionType(".epub", "application/epub+zip")
w.Header().Set("Content-Type", "application/epub+zip")
Accept .epub uploads
<input type="file" accept=".epub,application/epub+zip">
The accept attribute only filters the file picker; users can still choose another file. Listing the
extension as well as the type matters, because operating systems don’t always report the type you expect.
Related types
More documents
.doc , .docx , .xls , .xlsx , .ppt , .pptx , .odt , .rtf . Look up any extension or type with the MIME type lookup.
Sources
Spotted a mistake? Email hello@devtoolsmith.com and we’ll fix it.
Frequently asked questions
What is the MIME type for .epub files?
application/epub+zip. The full header is "Content-Type: application/epub+zip".
Why does my server send the wrong Content-Type for .epub?
Web servers pick the type from the file extension using a table (mime.types in nginx and Apache). If .epub is missing from that table, they send a default such as application/octet-stream or text/plain. Add the mapping as shown on this page, then check the response with "curl -sI".
How can I check that a file really is EPUB?
Look at the first bytes rather than the extension or the type the browser reports, which both come from the file name. EPUB files start with 50 4B 03 04, then "mimetypeapplication/epub+zip" from byte 30. The MIME type lookup on this site reads them for you when you drop a file on it.