Skip to content

XLSX files sent as binary/unknown type on WhatsApp - missing MIME type support #36

Closed

Description

@arun-8687

Description
When sending XLSX files via the MEDIA: directive, WhatsApp displays them as binary/unknown files instead of recognizing them as Excel spreadsheets. Users cannot open these files directly on mobile devices.

Root Cause
The mime.ts file lacks support for XLSX files in both:

  1. The EXT_BY_MIME mapping
  2. The sniffMime() function (no ZIP/PK magic byte detection)

Steps to Reproduce

  1. Create an XLSX file on the server
  2. Send it via agent reply using MEDIA:/path/to/file.xlsx
  3. Receive the file on WhatsApp mobile
  4. File shows as "BIN" or unknown type, cannot be opened

Expected Behavior
File should be recognized as an Excel spreadsheet and open in Excel/Google Sheets.

Proposed Fix
File: src/media/mime.ts

diff

const EXT_BY_MIME: Record<string, string> = {
   "image/jpeg": ".jpg",
   "image/png": ".png",
   "image/webp": ".webp",
   "image/gif": ".gif",
   "audio/ogg": ".ogg",
   "audio/mpeg": ".mp3",
   "video/mp4": ".mp4",
   "application/pdf": ".pdf",
   "text/plain": ".txt",
+  "text/csv": ".csv",
+  "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": ".xlsx",
 };

And in sniffMime():

diff

// MP4: "ftyp" at offset 4.
   if (buffer.length >= 12 && buffer.subarray(4, 8).toString("ascii") === "ftyp") {
     return "video/mp4";
   }
+  // ZIP/Office Open XML (xlsx, docx, pptx): PK\x03\x04
+  if (buffer[0] === 0x50 && buffer[1] === 0x4b && buffer[2] === 0x03 && buffer[3] === 0x04) {
+    return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
+  }
   return undefined;

Additional Context

  1. XLSX files are ZIP archives internally (PK magic bytes: 50 4B 03 04)
  2. This fix also enables potential support for other Office Open XML formats (docx, pptx) with minor additions
  3. The xlsx npm package can be used to create these files for agent skills

Labels
bug, enhancement, media

Activity

  1. added
    bug
    on Dec 20, 2025
  2. steipete commented on Dec 20, 2025

    @steipete
    Contributor

    thanks, fixed on main! 36c85a6

  3. added a commit that references this issue on Feb 2, 2026
  4. added a commit that references this issue on Feb 16, 2026
  5. added a commit that references this issue on Feb 25, 2026
  6. added a commit that references this issue on Mar 7, 2026
  7. locked as resolved and limited conversation to collaborators on Mar 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions