{"record":{"id":"4997760ddcf4662b","repo":"toeverything/AFFiNE","slug":"file-size-exceeds-the-formattedlimit-limit","errorCode":null,"errorMessage":"File size exceeds the ${formattedLimit}limit.","messagePattern":"File size exceeds the (.+?)limit\\.","errorType":"exception","errorClass":"OverSizeError","httpStatus":null,"severity":"error","filePath":"packages/common/nbstore/src/impls/cloud/blob.ts","lineNumber":135,"sourceCode":"      }\n\n      return {\n        key,\n        data: new Uint8Array(await blob.arrayBuffer()),\n        mime: blob.type,\n        size: blob.size,\n        createdAt: new Date(res.headers.get('last-modified') || Date.now()),\n      };\n    } catch (err) {\n      throw new Error('blob download error: ' + err);\n    }\n  }\n\n  override async set(blob: BlobRecord, signal?: AbortSignal) {\n    try {\n      const blobSizeLimit = await this.getBlobSizeLimit();\n      if (blob.data.byteLength > blobSizeLimit) {\n        throw new OverSizeError(this.humanReadableBlobSizeLimitCache);\n      }\n\n      const init = await this.connection.gql({\n        query: createBlobUploadMutation,\n        variables: {\n          workspaceId: this.options.id,\n          key: blob.key,\n          size: blob.data.byteLength,\n          mime: blob.mime,\n        },\n        context: { signal },\n      });\n\n      const upload = init.createBlobUpload;\n      if (upload.alreadyUploaded) {\n        return;\n      }\n      if (upload.method === BlobUploadMethod.GRAPHQL) {","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/b4c8548c09da21b2898443559a5b846f0ccf5dd8/packages/common/nbstore/src/impls/cloud/blob.ts#L117-L153","documentation":"CloudBlobStorage.set() pre-checks the blob's byteLength against the workspace's per-file blob size limit (fetched via workspaceBlobQuotaQuery) and throws OverSizeError before any network upload starts. The message embeds the human-readable limit, e.g. 'File size exceeds the 10 MB limit.' This is a client-side fast-fail to avoid uploading a file the server will reject.","triggerScenarios":"blobStorage.set({ key, data, mime }) where data.byteLength exceeds the server's configured blob size limit; uploading large videos/binaries/PDFs to a self-hosted AFFiNE whose AFFINE_BLOB_SIZE_LIMIT is at the default 10MB.","commonSituations":"Self-hosted server with default (small) blob limit; users attaching screen recordings or design files; changing the server limit but the client caching the old humanReadableBlobSizeLimitCache; plan-level per-file caps on affine.cloud.","solutions":["Reduce the file (compress images/video, split archives) below the limit stated in the message.","On a self-hosted server, raise the limit: set AFFINE_BLOB_SIZE_LIMIT (bytes) in the server env and restart — the client fetches the quota dynamically.","Check the workspace quota via storage.getBlobSizeLimit() in UI code and disable/warn on oversized picks before calling set.","If the message shows no limit value, the cached human-readable limit was null — re-fetch quota or treat the server response as the source of truth."],"exampleFix":"// before\nawait blobStorage.set({ key, data: fileBytes, mime: 'video/mp4' }); // throws\n\n// after\nconst limit = await blobStorage.getBlobSizeLimit();\nif (fileBytes.byteLength > limit) {\n  notify(`Max file size is ${formatBytes(limit)}`);\n} else {\n  await blobStorage.set({ key, data: fileBytes, mime: 'video/mp4' });\n}","handlingStrategy":"validation","validationCode":"const limit = await blobStorage.getBlobSizeLimit();\nif (file.size > limit) {\n  throw new Error(`file too large: ${file.size} > limit ${limit}`);\n}\nawait blobStorage.set({ key: nanoid(), data: bytes, mime });","typeGuard":"import { OverSizeError } from '@affine/nbstore/storage';\nconst isOverSize = (e: unknown): e is OverSizeError => e instanceof OverSizeError;","tryCatchPattern":"try { await blobStorage.set(rec); } catch (e) { if (e instanceof OverSizeError) { /* show 'file too large' with limit, offer compression */ return; } throw e; }","preventionTips":["Check getBlobSizeLimit() in the file-picker flow, not after upload starts","Compress media client-side before upload","Self-hosted: set AFFINE_BLOB_SIZE_LIMIT explicitly and document it for users"],"tags":["blob-storage","upload","size-limit","affine"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"b4c8548c09da21b2898443559a5b846f0ccf5dd8","analyzedAt":"2026-08-18T21:16:52.546Z","contentChangedAt":"2026-08-18T21:16:52.546Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}