{"record":{"id":"38276e9a07e7e3dd","repo":"Tencent/WeKnora","slug":"attachment-exceeds-the-d-mib-limit","errorCode":null,"errorMessage":"attachment exceeds the %d MiB limit","messagePattern":"attachment exceeds the (.+?) MiB limit","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/im/service.go","lineNumber":610,"sourceCode":"\t\tChannel:     \"im\",\n\t\tAttachments: messageAttachments,\n\t}\n}\n\ntype imDownloadedAttachment struct {\n\tfileName string\n\tcontent  []byte\n}\n\n// prepareIMAttachments downloads an IM attachment and exposes its parsed text\n// (and, for images, a bounded data URI) to the QA pipeline. This is separate\n// from the optional background knowledge-base save.\nfunc (s *Service) prepareIMAttachments(ctx context.Context, msg *IncomingMessage, adapter Adapter) (types.MessageAttachments, []string, *imDownloadedAttachment, error) {\n\tif msg.MessageType != MessageTypeFile && msg.MessageType != MessageTypeImage {\n\t\treturn nil, nil, nil, nil\n\t}\n\tif msg.FileSize > maxIMAttachmentBytes {\n\t\treturn nil, nil, nil, fmt.Errorf(\"attachment exceeds the %d MiB limit\", maxIMAttachmentBytes>>20)\n\t}\n\tdownloader, ok := adapter.(FileDownloader)\n\tif !ok {\n\t\treturn nil, nil, nil, fmt.Errorf(\"platform %s does not support attachment download\", msg.Platform)\n\t}\n\tattachmentCtx, cancel := context.WithTimeout(ctx, imAttachmentReadTimeout)\n\tdefer cancel()\n\treader, fileName, err := downloader.DownloadFile(attachmentCtx, msg)\n\tif err != nil {\n\t\treturn nil, nil, nil, err\n\t}\n\tdefer reader.Close()\n\tcontent, err := io.ReadAll(io.LimitReader(reader, maxIMAttachmentBytes+1))\n\tif err != nil {\n\t\treturn nil, nil, nil, err\n\t}\n\tif len(content) > maxIMAttachmentBytes {\n\t\treturn nil, nil, nil, fmt.Errorf(\"attachment exceeds the %d MiB limit\", maxIMAttachmentBytes>>20)","sourceCodeStart":592,"sourceCodeEnd":628,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/im/service.go#L592-L628","documentation":"prepareIMAttachments in internal/im/service.go rejects incoming file/image messages whose declared msg.FileSize exceeds maxIMAttachmentBytes before any download happens. The limit is reported in MiB (maxIMAttachmentBytes>>20). This is an early, cheap guard so oversized uploads never hit network I/O.","triggerScenarios":"An IM message of type file or image whose FileSize metadata exceeds maxIMAttachmentBytes is processed by the IM service.","commonSituations":"Users uploading large videos/archives to a bot channel; platforms reporting FileSize in bytes inconsistently; lowering/raising the limit constant without communicating it to channel users.","solutions":["Ask the user to send a smaller file (under the MiB limit shown in the error)","Compress or convert the attachment before sending","Raise maxIMAttachmentBytes if your storage/document-parser backend can handle larger files"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if msg.FileSize > maxIMAttachmentBytes {\n    reply(ctx, \"please send a file smaller than %d MiB\", maxIMAttachmentBytes>>20)\n    return\n}","typeGuard":null,"tryCatchPattern":"if err := s.prepareIMAttachments(ctx, msg, adapter); err != nil {\n    if strings.Contains(err.Error(), \"MiB limit\") {\n        // notify user their file is too large\n    }\n}","preventionTips":["Check the platform's max upload size and communicate the limit to channel users","Validate size client-side/bot-side before forwarding messages to the IM service"],"tags":["attachments","size-limit","validation"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}