MIME Types
File Formats
.docx
.pptx
Web Development

What is a correct MIME type for .docx, .pptx, etc.?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

The correct MIME type for .docx is application/vnd.openxmlformats-officedocument.wordprocessingml.document. For .pptx it is application/vnd.openxmlformats-officedocument.presentationml.presentation. For .xlsx it is application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.

These are the IANA-registered types for Office Open XML formats introduced in Microsoft Office 2007. They are distinct from the older binary formats (.doc, .xls, .ppt) and must be set correctly for downloads, uploads, and content negotiation to work in web applications.

Complete MIME Type Reference

The table below covers all commonly encountered Microsoft Office formats, both legacy binary and modern Open XML:

ExtensionFormatMIME Type
.docWord 97-2003application/msword
.docxWord 2007+application/vnd.openxmlformats-officedocument.wordprocessingml.document
.docmWord macro-enabledapplication/vnd.ms-word.document.macroEnabled.12
.dotWord template (legacy)application/msword
.dotxWord templateapplication/vnd.openxmlformats-officedocument.wordprocessingml.template
.xlsExcel 97-2003application/vnd.ms-excel
.xlsxExcel 2007+application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
.xlsmExcel macro-enabledapplication/vnd.ms-excel.sheet.macroEnabled.12
.xltxExcel templateapplication/vnd.openxmlformats-officedocument.spreadsheetml.template
.pptPowerPoint 97-2003application/vnd.ms-powerpoint
.pptxPowerPoint 2007+application/vnd.openxmlformats-officedocument.presentationml.presentation
.pptmPowerPoint macro-enabledapplication/vnd.ms-powerpoint.presentation.macroEnabled.12
.potxPowerPoint templateapplication/vnd.openxmlformats-officedocument.presentationml.template

Why the MIME Types Are So Long

Office Open XML MIME types follow the IANA vnd. (vendor) naming convention. The structure breaks down as:

text
application/vnd.openxmlformats-officedocument.wordprocessingml.document
|           |                                 |                 |
type        vendor tree                       sub-format        specific type
  • application is the top-level type for binary/structured data.
  • vnd.openxmlformats-officedocument identifies the vendor and format family.
  • wordprocessingml / spreadsheetml / presentationml identifies the Office application.
  • document / sheet / presentation / template identifies the specific document type.

This verbose naming is intentional. It prevents ambiguity between document types that might otherwise share a generic type like application/xml.

Setting MIME Types in Web Servers

Nginx

nginx
1types {
2    application/vnd.openxmlformats-officedocument.wordprocessingml.document  docx;
3    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet       xlsx;
4    application/vnd.openxmlformats-officedocument.presentationml.presentation pptx;
5    application/msword                                                       doc;
6    application/vnd.ms-excel                                                 xls;
7    application/vnd.ms-powerpoint                                            ppt;
8}

Most Nginx installations include these mappings via /etc/nginx/mime.types. Check that file before adding custom types to avoid duplicates.

Apache

Apache's mod_mime uses AddType directives. These are typically already present in the default mime.types file, but you can add them explicitly:

apache
AddType application/vnd.openxmlformats-officedocument.wordprocessingml.document .docx
AddType application/vnd.openxmlformats-officedocument.spreadsheetml.sheet .xlsx
AddType application/vnd.openxmlformats-officedocument.presentationml.presentation .pptx

Express.js (Node.js)

Express uses the mime package internally. Modern versions handle Office formats correctly by default. To override or verify:

javascript
1const express = require('express');
2const app = express();
3
4// Express serves static files with correct MIME types automatically
5app.use(express.static('public'));
6
7// For manual file responses, set the Content-Type explicitly
8app.get('/download/:filename', (req, res) => {
9  const mimeTypes = {
10    '.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
11    '.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
12    '.pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
13  };
14
15  const ext = path.extname(req.params.filename);
16  const contentType = mimeTypes[ext] || 'application/octet-stream';
17  res.setHeader('Content-Type', contentType);
18  res.sendFile(path.join(__dirname, 'files', req.params.filename));
19});

Setting MIME Types for File Uploads

When accepting file uploads, validate the MIME type on the server side. Do not rely solely on the Content-Type header sent by the browser, because clients can set it to anything.

Python (Flask)

python
1from flask import Flask, request, jsonify
2
3ALLOWED_MIME_TYPES = {
4    'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
5    'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
6    'application/vnd.openxmlformats-officedocument.presentationml.presentation',
7}
8
9@app.route('/upload', methods=['POST'])
10def upload_file():
11    file = request.files.get('document')
12    if not file:
13        return jsonify(error='No file provided'), 400
14
15    if file.content_type not in ALLOWED_MIME_TYPES:
16        return jsonify(error='Invalid file type'), 415
17
18    file.save(f'./uploads/{file.filename}')
19    return jsonify(status='uploaded'), 200

Java (Spring Boot)

java
1@PostMapping("/upload")
2public ResponseEntity<String> uploadFile(@RequestParam("file") MultipartFile file) {
3    String contentType = file.getContentType();
4    Set<String> allowed = Set.of(
5        "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
6        "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
7        "application/vnd.openxmlformats-officedocument.presentationml.presentation"
8    );
9
10    if (!allowed.contains(contentType)) {
11        return ResponseEntity.status(415).body("Unsupported file type");
12    }
13
14    // Process file
15    return ResponseEntity.ok("File uploaded");
16}

Content-Disposition for Downloads

When serving Office files for download, set both Content-Type and Content-Disposition headers to ensure the browser downloads the file rather than trying to display it:

http
Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
Content-Disposition: attachment; filename="report.docx"

Without Content-Disposition: attachment, some browsers may attempt to open the file in a browser-based viewer or plugin, which may not be the intended behavior.

OOXML Files Are ZIP Archives

A useful fact for debugging: .docx, .xlsx, and .pptx files are ZIP archives containing XML files, media, and metadata. You can verify this:

bash
1file report.docx
2# report.docx: Microsoft Word 2007+
3
4unzip -l report.docx
5# Archive:  report.docx
6#   Length      Date    Time    Name
7# ---------  ---------- -----   ----
8#      1312  2024-01-15 10:30   [Content_Types].xml
9#       590  2024-01-15 10:30   _rels/.rels
10#      2847  2024-01-15 10:30   word/document.xml
11#       ...

This means that if a server sends application/zip for a .docx file, the file will download correctly but the operating system may not associate it with Word. The correct MIME type ensures the OS opens the right application.

Legacy vs Modern Format Comparison

FeatureLegacy (.doc/.xls/.ppt)Open XML (.docx/.xlsx/.pptx)
Internal formatProprietary binaryZIP of XML files
File sizeGenerally largerSmaller (compressed)
Programmatic accessRequires specialized parsersStandard XML/ZIP tools work
Macro supportBuilt-inSeparate extension (.docm, .xlsm)
RecoveryDifficult if corruptedIndividual XML parts may be recoverable
MIME prefixapplication/msword, application/vnd.ms-*application/vnd.openxmlformats-*

Other office suites have their own MIME types that you may need to handle alongside Microsoft formats:

ExtensionApplicationMIME Type
.odtOpenDocument Textapplication/vnd.oasis.opendocument.text
.odsOpenDocument Spreadsheetapplication/vnd.oasis.opendocument.spreadsheet
.odpOpenDocument Presentationapplication/vnd.oasis.opendocument.presentation
.pdfPDFapplication/pdf

Common Pitfalls

Using application/octet-stream as a catch-all. This tells the browser "unknown binary data," which forces a download but prevents the OS from opening the file with the correct application. Always use the specific MIME type.

Serving .docx with application/msword. That is the MIME type for the legacy .doc format. While some applications handle the mismatch gracefully, others will reject the file or display an error.

Not validating MIME types on upload. The Content-Type header from the browser is user-controlled and can be spoofed. For security-sensitive applications, validate the file contents (check for the ZIP magic bytes PK and the [Content_Types].xml entry) rather than trusting the header alone.

Forgetting macro-enabled variants. Files with macros (.docm, .xlsm, .pptm) have different MIME types than their non-macro counterparts. If your application blocks macro-enabled uploads for security reasons, these must be checked separately.

Missing MIME types in cloud storage configuration. When serving files from S3, GCS, or Azure Blob Storage, the MIME type is stored as object metadata. If it was not set correctly during upload, downloads will use application/octet-stream by default. Set the Content-Type metadata explicitly during upload.

Summary

  • .docx uses application/vnd.openxmlformats-officedocument.wordprocessingml.document.
  • .xlsx uses application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.
  • .pptx uses application/vnd.openxmlformats-officedocument.presentationml.presentation.
  • Legacy formats (.doc, .xls, .ppt) use shorter MIME types like application/msword.
  • Always set both Content-Type and Content-Disposition when serving files for download.
  • Validate MIME types on the server during uploads. Do not trust client-sent headers alone.
  • OOXML files are ZIP archives internally, which is why application/zip technically works but produces incorrect OS behavior.

Course illustration
Course illustration

All Rights Reserved.