gitroomhq/postiz-app · error · BadRequestException

File size exceeds the maximum allowed size of ${maxSize} byt

Error message

File size exceeds the maximum allowed size of ${maxSize} bytes.

What it means

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.

Source

Thrown at libraries/nestjs-libraries/src/upload/custom.upload.validation.ts:43

    }

    // Skip non-file parameters (org, body, query, etc.)
    if (!('buffer' in value) && !('mimetype' in value) && !('fieldname' in value)) {
      return value;
    }

    if (!value.buffer || !Buffer.isBuffer(value.buffer)) {
      throw new BadRequestException('Invalid file upload.');
    }

    const detected = await fileTypeFromBuffer(value.buffer);
    if (!detected || !ALLOWED_MIME_TYPES.has(detected.mime)) {
      throw new BadRequestException('Unsupported file type.');
    }

    const maxSize = getMaxSize(detected.mime);
    if (value.size > maxSize) {
      throw new BadRequestException(
        `File size exceeds the maximum allowed size of ${maxSize} bytes.`
      );
    }

    value.mimetype = detected.mime;
    const safeBase = (value.originalname || 'upload')
      .replace(/\.[^./\\]*$/, '')
      .replace(/[\\/]/g, '_')
      .slice(0, 100) || 'upload';
    value.originalname = `${safeBase}.${detected.ext}`;

    return value;
  }

}

export function getMaxSize(mimeType: string): number {
  if (mimeType.startsWith('image/')) {

View on GitHub (pinned to 0f1647f749)

Solutions

  1. Compress or resize images client-side to under 10 MB (e.g. canvas re-encode at quality 0.85)
  2. Trim/compress videos over 1 GB before uploading
  3. Raise the limit in getMaxSize if business needs require it (and check any reverse-proxy body size limits like nginx client_max_body_size)
  4. Show the limit in the UI upload dialog so users know beforehand

Example fix

// before: raw upload
await fetch('/upload', { method: 'POST', body: formData });

// after: client-side downscale
const blob = await compressImage(file, { maxSizeMB: 9 });
formData.set('file', blob, 'photo.jpg');
await fetch('/upload', { method: 'POST', body: formData });
Defensive patterns

Strategy: validation

Validate before calling

const MAX_IMAGE = 10 * 1024 * 1024;
function isWithinLimit(file: File): boolean {
  return file.size <= (file.type.startsWith('video/') ? 1024**3 : MAX_IMAGE);
}

Type guard

const isUnderSizeLimit = (size: number, mime: string): boolean => size <= (mime.startsWith('video/') ? 1024*1024*1024 : 10*1024*1024);

Try / catch

try { await api.upload(form); } catch (e) { if (/File size exceeds/.test(String(e))) notify('Image max 10MB, video max 1GB'); else throw e; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of gitroomhq/postiz-app@0f1647f749 (2026-08-27). Data as JSON: /api/errors/f4696ec15b46d381. Report an issue: GitHub.