Skip to content

Attachment uploads don't record the content type #48

Open

Description

@markmnl

Problem

POST /fmsg/:id/attach (AttachmentHandler.Upload) stores the file and inserts the msg_attachment row without a type:

`INSERT INTO msg_attachment (msg_id, filename, filesize, filepath)
VALUES ($1, $2, $3, $4)
ON CONFLICT (msg_id, filename) DO UPDATE SET filesize=$3, filepath=$4`,
msgID, intendedFilename, written, finalPath,

So every uploaded attachment keeps the schema default, application/octet-stream. That's the type that goes on the wire in the fmsg message and the one returned by the message and thread endpoints. Meanwhile, GET /fmsg/:id/attach/:filename serves the file with a type inferred from its extension. Clients see the same attachment with two different types, depending on which endpoint they ask.

Reported by an MCP client that sent spark.png with image/png:

  • the thread view listed it as application/octet-stream;
  • the download returned image/png.

Suggested fix

  • Store a content type on upload. Use the multipart part's Content-Type when it's a valid, specific media type, otherwise infer one from the filename extension (mime.TypeByExtension). Fall back to application/octet-stream only when neither gives a type.
  • Persist it in msg_attachment.type (insert, and the ON CONFLICT update).
  • Optionally, validate the result with mime.ParseMediaType.

Existing rows keep application/octet-stream. Clients can keep inferring from the extension for those.

🤖 Generated with Claude Code

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions