About Word document files
A .docx file is a ZIP archive of XML files (Office Open XML). That long type name is the only one Office and browsers recognise; servers that don’t know it often send application/zip or application/octet-stream, and the file then downloads with a .zip extension in some browsers.
-
To tell .docx, .xlsx and .pptx apart without trusting the extension, open the ZIP and look for
word/,xl/orppt/folders. -
Templates (.dotx) and macro-enabled documents (.docm) have their own types:
…wordprocessingml.templateandapplication/vnd.ms-word.document.macroEnabled.12.
File signature
DOCX files start with 50 4B 03 04 ("PK", a ZIP archive). 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 .docx with the right Content-Type
Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
application/vnd.openxmlformats-officedocument.wordprocessingml.document docx;
AddType application/vnd.openxmlformats-officedocument.wordprocessingml.document .docx
@docx path *.docx
header @docx Content-Type "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
curl -sI https://example.com/file.docx | grep -i '^content-type'
# Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
Set the type in code
res.set('Content-Type', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document');
// Or make the browser download it:
res.attachment('file.docx');
import mimetypes
mimetypes.add_type('application/vnd.openxmlformats-officedocument.wordprocessingml.document', '.docx') # if your system doesn't know it
mimetypes.guess_type('file.docx')[0] # 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
mime.AddExtensionType(".docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
w.Header().Set("Content-Type", "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
Accept .docx uploads
<input type="file" accept=".docx,application/vnd.openxmlformats-officedocument.wordprocessingml.document">
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
-
.doc (
application/msword): Word 97–2003 document -
.xlsx (
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet): Excel workbook -
.pptx (
application/vnd.openxmlformats-officedocument.presentationml.presentation): PowerPoint presentation -
.odt (
application/vnd.oasis.opendocument.text): OpenDocument text
More documents
.pdf , .xls , .ppt , .rtf , .epub . Look up any extension or type with the MIME type lookup.
Sources
- IANA registration: application/vnd.openxmlformats-officedocument.wordprocessingml.document
- MDN: Common media types
Spotted a mistake? Email hello@devtoolsmith.com and we’ll fix it.
Frequently asked questions
What is the MIME type for .docx files?
application/vnd.openxmlformats-officedocument.wordprocessingml.document. The full header is "Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document".
Why does my server send the wrong Content-Type for .docx?
Web servers pick the type from the file extension using a table (mime.types in nginx and Apache). If .docx 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 DOCX?
Look at the first bytes rather than the extension or the type the browser reports, which both come from the file name. DOCX files start with 50 4B 03 04 ("PK", a ZIP archive). The MIME type lookup on this site reads them for you when you drop a file on it.