Tencent/WeKnora · error
attachment exceeds the %d MiB limit
Error message
attachment exceeds the %d MiB limit
What it means
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.
Source
Thrown at internal/im/service.go:610
Channel: "im",
Attachments: messageAttachments,
}
}
type imDownloadedAttachment struct {
fileName string
content []byte
}
// prepareIMAttachments downloads an IM attachment and exposes its parsed text
// (and, for images, a bounded data URI) to the QA pipeline. This is separate
// from the optional background knowledge-base save.
func (s *Service) prepareIMAttachments(ctx context.Context, msg *IncomingMessage, adapter Adapter) (types.MessageAttachments, []string, *imDownloadedAttachment, error) {
if msg.MessageType != MessageTypeFile && msg.MessageType != MessageTypeImage {
return nil, nil, nil, nil
}
if msg.FileSize > maxIMAttachmentBytes {
return nil, nil, nil, fmt.Errorf("attachment exceeds the %d MiB limit", maxIMAttachmentBytes>>20)
}
downloader, ok := adapter.(FileDownloader)
if !ok {
return nil, nil, nil, fmt.Errorf("platform %s does not support attachment download", msg.Platform)
}
attachmentCtx, cancel := context.WithTimeout(ctx, imAttachmentReadTimeout)
defer cancel()
reader, fileName, err := downloader.DownloadFile(attachmentCtx, msg)
if err != nil {
return nil, nil, nil, err
}
defer reader.Close()
content, err := io.ReadAll(io.LimitReader(reader, maxIMAttachmentBytes+1))
if err != nil {
return nil, nil, nil, err
}
if len(content) > maxIMAttachmentBytes {
return nil, nil, nil, fmt.Errorf("attachment exceeds the %d MiB limit", maxIMAttachmentBytes>>20)View on GitHub (pinned to 988cbb0330)
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
Defensive patterns
Strategy: validation
Validate before calling
if msg.FileSize > maxIMAttachmentBytes {
reply(ctx, "please send a file smaller than %d MiB", maxIMAttachmentBytes>>20)
return
} Try / catch
if err := s.prepareIMAttachments(ctx, msg, adapter); err != nil {
if strings.Contains(err.Error(), "MiB limit") {
// notify user their file is too large
}
} Prevention
- 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
When it happens
Trigger: An IM message of type file or image whose FileSize metadata exceeds maxIMAttachmentBytes is processed by the IM service.
Common situations: 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.
Understand the failure class
Background: "File too large" / "file size exceeds limit" errors: why libraries cap file sizes and how to fix them — this error's family across 46 libraries.
Related errors
- a message can use at most %d attachments
- attachment has no file extension
- invite code has expired
- join request not found
- failed to retrieve: %s
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/38276e9a07e7e3dd.
Report an issue: GitHub.