Skip to content

[Bug] chat_attachment.mime_type varchar(64) 装不下 OOXML MIME,docx/xlsx/pptx 附件上传必现失败 #358

Open

Description

@garminx

[Bug] chat_attachment.mime_type varchar(64) 装不下 OOXML MIME,docx/xlsx/pptx 附件上传必现失败

现象

HiChat / HiCoding 上传 Office 文档附件(.docx/.xlsx/.pptx)100% 失败,返回:

Internal server error: Failed to upload attachment: could not execute statement
[(conn=xxxx) Data too long for column 'mime_type' at row 1]
[insert into chat_attachment (attachment_id,created_at,data,mime_type,name,size,type,updated_at,user_id) values (?,?,?,?,?,?,?,?,?)]

chat_attachment 表在我们的部署中 0 行——该功能从未成功过。

根因

标准 OOXML MIME 类型长度超过列宽 varchar(64):

MIME 长度
application/vnd.openxmlformats-officedocument.wordprocessingml.document (.docx) 71
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet (.xlsx) 65
application/vnd.openxmlformats-officedocument.presentationml.presentation (.pptx) 73

写入链路(服务端原样存 part 的 Content-Type,无截断):

  • himarket-server/src/main/java/com/alibaba/himarket/service/impl/ChatAttachmentServiceImpl.java L65-L76:mimeType = file.getContentType() → .mimeType(mimeType)
  • 实体 ChatAttachment.java L86:@Column(name = "mime_type", length = 64)
  • 建表 himarket-bootstrap/src/main/resources/db/migration/V3__Add_chat_tables.sql L59:mime_type varchar(64)(V5 只补了时间戳列,未动列宽)

text/plain(10)/image/png(9) 等短类型不受影响,因此问题只在 Office 文档上暴露。

修复建议

  1. 新增 Flyway 迁移:ALTER TABLE chat_attachment MODIFY mime_type VARCHAR(255)(RFC 6838 媒体类型建议上限 255),同步把实体 length = 64 改 255;
  2. 可选加固:服务端入库前对超长 mime 做截断/规范化,避免未来再次出现同类 500。

环境

  • himarket-server: opensource-registry.cn-hangzhou.cr.aliyuncs.com/higress-group/himarket-server@sha256:f51b41da3e0428aedd0495140583e424faee2e3a9ccab1978dd86cbc679f3a6e(Flyway V1-V22 已全部应用)
  • 本地核对源码分支 main(与 origin/main 同步,含 fix: skip nested required array when converting mcp tool args #352)

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