fix(wiki): widen mime_type to VARCHAR(255) so Office uploads don't blow the column

This commit is contained in:
matevip 2026-05-02 23:11:40 +08:00
parent c60fc4cf83
commit 29d2d49d25
3 changed files with 32 additions and 1 deletions

View File

@ -154,7 +154,7 @@ public class WikiRawMaterialService {
entity.setKbId(kbId);
entity.setTitle(title);
entity.setSourceType(sourceType);
entity.setMimeType(mimeType);
entity.setMimeType(capMimeType(mimeType));
entity.setSourcePath(sourcePath);
entity.setFileSize(fileSize);
entity.setProcessingStatus("pending");
@ -195,6 +195,23 @@ public class WikiRawMaterialService {
return entity;
}
/**
* Defensive cap on the persisted Content-Type so a long upload header
* never blocks the insert. The column itself is wide (V84 VARCHAR(255))
* but capping at the service layer keeps the schema and the writer in
* lockstep we'd rather drop the rare overlong header (chrome-derived
* Content-Type with charset / boundary parameters) than fail the upload.
*/
private static final int MIME_TYPE_MAX_CHARS = 255;
private static String capMimeType(String mimeType) {
if (mimeType == null) return null;
if (mimeType.length() <= MIME_TYPE_MAX_CHARS) return mimeType;
log.warn("[Wiki] Truncating Content-Type ({} chars) to fit storage column: {}",
mimeType.length(), mimeType.substring(0, 60) + "");
return mimeType.substring(0, MIME_TYPE_MAX_CHARS);
}
/**
* CAS 式抢占仅当当前状态为 pending 时才更新为 processing
*

View File

@ -0,0 +1,7 @@
-- V80 created mate_wiki_raw_material.mime_type as VARCHAR(64). Office Open
-- XML Content-Types blow that on the very first upload — docx is 71 chars,
-- pptx is 73, xlsx is 65 — so any user uploading a Word / Excel / PowerPoint
-- file hits "Data truncation: Data too long for column 'mime_type'".
-- Widen to 255 (covers any registered RFC 6838 type with parameters).
ALTER TABLE mate_wiki_raw_material ALTER COLUMN mime_type SET DATA TYPE VARCHAR(255);

View File

@ -0,0 +1,7 @@
-- V80 created mate_wiki_raw_material.mime_type as VARCHAR(64). Office Open
-- XML Content-Types blow that on the very first upload — docx is 71 chars,
-- pptx is 73, xlsx is 65 — so any user uploading a Word / Excel / PowerPoint
-- file hits "Data truncation: Data too long for column 'mime_type'".
-- Widen to 255 (covers any registered RFC 6838 type with parameters).
ALTER TABLE mate_wiki_raw_material MODIFY COLUMN mime_type VARCHAR(255);