transloadit/uppy · error · ValidationError

incorrect chunkSize

Error message

incorrect chunkSize

What it means

Uploader.validateOptions enforces that options.chunkSize, when present, must be a number. It is intended to be set server-side from Companion's chunkSize config; a non-numeric value (string, boolean, object) throws ValidationError 'incorrect chunkSize'.

Source

Thrown at packages/@uppy/companion/src/server/Uploader.ts:175

      if (url == null) return
      const validatorOpts = { require_protocol: true, require_tld: false }
      if (!validator.isURL(url, validatorOpts)) {
        throw new ValidationError('invalid destination url')
      }

      const allowedUrls = options.companionOptions.uploadUrls
      if (allowedUrls && !hasMatch(url, allowedUrls)) {
        throw new ValidationError(
          'upload destination does not match any allowed destinations',
        )
      }
    }

    ;[options.endpoint, options.uploadUrl].forEach(validateUrl)
  }

  if (options.chunkSize != null && typeof options.chunkSize !== 'number') {
    throw new ValidationError('incorrect chunkSize')
  }
}

const states = {
  idle: 'idle',
  uploading: 'uploading',
  paused: 'paused',
  done: 'done',
}

export default class Uploader {
  static FILE_NAME_PREFIX = 'uppy-file'

  static STORAGE_PREFIX = 'companion'

  storage: Redis | null | undefined

  providerName: string | undefined

View on GitHub (pinned to 5d4dedd02a)

Solutions

  1. Pass chunkSize as a number: chunkSize: 1024 (or omit it)
  2. If sourced from an env var, convert with Number.parseInt/Number() and validate before use
  3. Audit custom code that builds Uploader options directly

Example fix

// before
new Uploader({ ..., chunkSize: process.env.CHUNK_SIZE })

// after
new Uploader({ ..., chunkSize: Number.parseInt(process.env.CHUNK_SIZE ?? '0', 10) || undefined })
Defensive patterns

Strategy: type-guard

Validate before calling

if (opts.chunkSize != null && typeof opts.chunkSize !== 'number') {
  opts.chunkSize = Number(opts.chunkSize)
}

Type guard

const isNumericChunkSize = (v: unknown): v is number => v == null || typeof v === 'number';

Prevention

When it happens

Trigger: Constructing Uploader with chunkSize: '1024' (string) or another non-number type; or a Companion config layer that reads chunkSize from an env var without converting it to a number and passes it through.

Common situations: Setting COMPANION_CHUNK_SIZE as an env var (always a string) and having custom code inject it un-parsed; programmatic use of the Uploader class outside the standard reqToOptions path.

Related errors


AI-assisted analysis of transloadit/uppy@5d4dedd02a (2026-08-28). Data as JSON: /api/errors/b1dfdb39ba3d6101. Report an issue: GitHub.