toeverything/AFFiNE · error · CommentAttachmentQuotaExceeded
comment_attachment_quota_exceeded
comment_attachment_quota_exceeded
Error message
You have exceeded the comment attachment size quota.
What it means
Mutation uploadCommentAttachment (resolver.ts:361-363) buffers the whole upload and rejects it with CommentAttachmentQuotaExceeded when buffer.length exceeds 10 * 1024 * 1024 bytes. This is the hard per-file cap, enforced before the workspace quota calculator runs.
Solutions
- Compress or downscale the attachment below 10 MiB before uploading.
- Add a client-side File.size > 10*1024*1024 check and block the upload early.
- For bigger files, store them in doc cloud storage/drive instead of a comment attachment.
Example fix
// before
const url = await uploadCommentAttachment(workspaceId, docId, file); // 25MB video -> error
// after
const MAX = 10 * 1024 * 1024;
if (file.size > MAX) throw new Error('Attachment must be under 10MB');
const url = await uploadCommentAttachment(workspaceId, docId, file); Defensive patterns
Strategy: validation
Validate before calling
const MAX_ATTACHMENT_BYTES = 10 * 1024 * 1024;
if (file.size > MAX_ATTACHMENT_BYTES) {
alert('Attachment must be 10MB or smaller');
return;
}
const url = await uploadCommentAttachment(workspaceId, docId, file); Try / catch
try {
await uploadCommentAttachment(workspaceId, docId, file);
} catch (e) {
if (getErrorCode(e) === 'comment_attachment_quota_exceeded' && file.size > 10 * 1024 * 1024) {
// too big: compress/downscale and retry with the smaller file
} else throw e;
} Prevention
- Check File.size against 10 MiB in the picker before any network call.
- Compress images/video before attaching to comments.
- The server measures the raw buffered stream, not the on-disk compressed size.
When it happens
Trigger: Calling uploadCommentAttachment with a GraphQLUpload whose streamed bytes total more than 10 MiB - large screenshots, screen recordings, or PDFs attached to a comment.
Common situations: Attaching raw photos/videos from a phone; assuming the limit applies to compressed size (it is the raw buffered stream size); no client-side size check before upload.
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
AI-assisted analysis of toeverything/AFFiNE@b4c8548c09 (2026-08-18).
Data as JSON: /api/errors/7b01f6b46736511d.
Report an issue: GitHub.
Appendix: source
Thrown at packages/backend/server/src/core/comment/resolver.ts:362
description: 'Upload a comment attachment and return the access url',
})
async uploadCommentAttachment(
@CurrentUser() me: UserType,
@Args('workspaceId') workspaceId: string,
@Args('docId') docId: string,
@Args({ name: 'attachment', type: () => GraphQLUpload })
attachment: FileUpload
) {
await this.assertPermission(
me,
{ workspaceId, docId },
'Doc.Comments.Create'
);
const buffer = await readableToBuffer(attachment.createReadStream());
// max attachment size is 10MB
if (buffer.length > 10 * 1024 * 1024) {
throw new CommentAttachmentQuotaExceeded();
}
const checkExceeded =
await this.quota.getWorkspaceQuotaCalculator(workspaceId);
const result = checkExceeded(buffer.length);
if (result?.blobQuotaExceeded || result?.storageQuotaExceeded) {
throw new CommentAttachmentQuotaExceeded();
}
const key = randomUUID();
await this.commentAttachmentStorage.put(
workspaceId,
docId,
key,
attachment.filename ?? key,
buffer,
me.id
);View on GitHub (pinned to b4c8548c09)