{"record":{"id":"f4696ec15b46d381","repo":"gitroomhq/postiz-app","slug":"file-size-exceeds-the-maximum-allowed-size-of-ma","errorCode":null,"errorMessage":"File size exceeds the maximum allowed size of ${maxSize} bytes.","messagePattern":"File size exceeds the maximum allowed size of (.+?) bytes\\.","errorType":"validation","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"libraries/nestjs-libraries/src/upload/custom.upload.validation.ts","lineNumber":43,"sourceCode":"    }\n\n    // Skip non-file parameters (org, body, query, etc.)\n    if (!('buffer' in value) && !('mimetype' in value) && !('fieldname' in value)) {\n      return value;\n    }\n\n    if (!value.buffer || !Buffer.isBuffer(value.buffer)) {\n      throw new BadRequestException('Invalid file upload.');\n    }\n\n    const detected = await fileTypeFromBuffer(value.buffer);\n    if (!detected || !ALLOWED_MIME_TYPES.has(detected.mime)) {\n      throw new BadRequestException('Unsupported file type.');\n    }\n\n    const maxSize = getMaxSize(detected.mime);\n    if (value.size > maxSize) {\n      throw new BadRequestException(\n        `File size exceeds the maximum allowed size of ${maxSize} bytes.`\n      );\n    }\n\n    value.mimetype = detected.mime;\n    const safeBase = (value.originalname || 'upload')\n      .replace(/\\.[^./\\\\]*$/, '')\n      .replace(/[\\\\/]/g, '_')\n      .slice(0, 100) || 'upload';\n    value.originalname = `${safeBase}.${detected.ext}`;\n\n    return value;\n  }\n\n}\n\nexport function getMaxSize(mimeType: string): number {\n  if (mimeType.startsWith('image/')) {","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/gitroomhq/postiz-app/blob/0f1647f7491a217d43eb5ae7a480484bdf0aff3e/libraries/nestjs-libraries/src/upload/custom.upload.validation.ts#L25-L61","documentation":"The upload validation pipe compares value.size against getMaxSize(detected.mime): 10 MB for images, 1 GB for video. If the uploaded file exceeds the cap for its sniffed type, this 400 BadRequestException is thrown. Note the size check uses the Multer-reported size, which can differ slightly from buffer length after transformations.","triggerScenarios":"Uploading an image larger than 10 MB (e.g. a 15 MB camera photo) or a video larger than 1 GB. Also triggered when multiple files each under the limit are validated one-by-one but a single oversized one fails the whole request.","commonSituations":"Modern phone photos (HEIC converted to JPEG often 8-15 MB); screenshots exported at very high resolution; long screen recordings exceeding 1 GB; client-side not enforcing size before upload.","solutions":["Compress or resize images client-side to under 10 MB (e.g. canvas re-encode at quality 0.85)","Trim/compress videos over 1 GB before uploading","Raise the limit in getMaxSize if business needs require it (and check any reverse-proxy body size limits like nginx client_max_body_size)","Show the limit in the UI upload dialog so users know beforehand"],"exampleFix":"// before: raw upload\nawait fetch('/upload', { method: 'POST', body: formData });\n\n// after: client-side downscale\nconst blob = await compressImage(file, { maxSizeMB: 9 });\nformData.set('file', blob, 'photo.jpg');\nawait fetch('/upload', { method: 'POST', body: formData });","handlingStrategy":"validation","validationCode":"const MAX_IMAGE = 10 * 1024 * 1024;\nfunction isWithinLimit(file: File): boolean {\n  return file.size <= (file.type.startsWith('video/') ? 1024**3 : MAX_IMAGE);\n}","typeGuard":"const isUnderSizeLimit = (size: number, mime: string): boolean => size <= (mime.startsWith('video/') ? 1024*1024*1024 : 10*1024*1024);","tryCatchPattern":"try { await api.upload(form); } catch (e) { if (/File size exceeds/.test(String(e))) notify('Image max 10MB, video max 1GB'); else throw e; }","preventionTips":["Compress images client-side before upload","Show size limits in the upload UI","Keep reverse-proxy client_max_body_size >= app limit"],"tags":["upload","file-size","validation","limits"],"backgroundTag":"file-too-large","analyzedSha":"0f1647f7491a217d43eb5ae7a480484bdf0aff3e","analyzedAt":"2026-08-27T12:09:55.020Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}