{"record":{"id":"8bc2703c7fbd2218","repo":"toeverything/AFFiNE","slug":"image-could-not-be-decoded","errorCode":null,"errorMessage":"Image could not be decoded","messagePattern":"Image could not be decoded","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/frontend/core/src/utils/reduce-image.ts","lineNumber":13,"sourceCode":"import reduce from 'image-blob-reduce';\n\n// validate and reduce image size and return as file\nexport const validateAndReduceImage = async (file: File): Promise<File> => {\n  // Declare a new async function that wraps the decode logic\n  const decodeAndReduceImage = async (): Promise<Blob> => {\n    const img = new Image();\n    const url = URL.createObjectURL(file);\n    img.src = url;\n\n    await img.decode().catch(() => {\n      URL.revokeObjectURL(url);\n      throw new Error('Image could not be decoded');\n    });\n\n    img.onload = img.onerror = () => {\n      URL.revokeObjectURL(url);\n    };\n\n    const sizeInMB = file.size / (1024 * 1024);\n    if (sizeInMB > 10 || img.width > 4000 || img.height > 4000) {\n      // Compress the file to less than 10MB\n\n      try {\n        const compressedImg = await reduce().toBlob(file, {\n          max: 4000,\n          unsharpAmount: 80,\n          unsharpRadius: 0.6,\n          unsharpThreshold: 2,\n        });\n        return compressedImg;","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/b4c8548c09da21b2898443559a5b846f0ccf5dd8/packages/frontend/core/src/utils/reduce-image.ts#L1-L31","documentation":"decodeAndReduceImage loads the file into an Image and awaits img.decode(); if decoding fails (corrupt or unsupported image data) the catch revokes the object URL and throws this Error before any reduction is attempted.","triggerScenarios":"Thrown in validateAndReduceImage when img.decode() rejects, i.e. the browser cannot decode the selected file as an image before size reduction.","commonSituations":"A user uploads a file that is not a valid or supported image (corrupted file or unsupported format). Choose a standard image format such as PNG or JPEG and retry.","solutions":["Check the image file is a supported, non-corrupt format.","Convert the image to PNG/JPEG and retry."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b4c8548c09da21b2898443559a5b846f0ccf5dd8","analyzedAt":"2026-08-18T21:16:52.546Z","contentChangedAt":"2026-08-18T21:16:52.546Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}