transloadit/uppy · error · Error

File data is empty

Error message

File data is empty

What it means

createThumbnail throws when file.data is null/undefined — there is no Blob to load into an Image for downscaling. Typically the file object exists in state but its raw data was stripped (e.g. after a page restore or programmatic reconstruction), so a thumbnail cannot be generated.

Source

Thrown at packages/@uppy/thumbnail-generator/src/index.ts:208

    this.thumbnailType = this.opts.thumbnailType

    this.defaultLocale = locale

    this.i18nInit()

    if (this.opts.lazy && this.opts.waitForThumbnailsBeforeUpload) {
      throw new Error(
        'ThumbnailGenerator: The `lazy` and `waitForThumbnailsBeforeUpload` options are mutually exclusive. Please ensure at most one of them is set to `true`.',
      )
    }
  }

  createThumbnail(
    file: LocalUppyFile<M, B>,
    targetWidth: number | null,
    targetHeight: number | null,
  ): Promise<string> {
    if (file.data == null) throw new Error('File data is empty')
    const originalUrl = URL.createObjectURL(file.data)

    const onload = new Promise<HTMLImageElement>((resolve, reject) => {
      const image = new Image()
      image.src = originalUrl
      image.addEventListener('load', () => {
        URL.revokeObjectURL(originalUrl)
        resolve(image)
      })
      image.addEventListener('error', (event) => {
        URL.revokeObjectURL(originalUrl)
        reject(event.error || new Error('Could not create thumbnail'))
      })
    })

    const orientationPromise = rotation(file.data).catch(
      () => 1,
    ) as Promise<Rotation>

View on GitHub (pinned to 5d4dedd02a)

Solutions

  1. Guard before requesting thumbnails: skip files with no data in a thumbnail:all handler or your custom scheduling
  2. Ensure uppy.addFile is always given a real Blob/File in data
  3. After Golden Retriever restores, mark restored files as not previewable or let users re-add them
  4. Catch per-file thumbnail errors ('thumbnail:error') instead of letting them reject globally

Example fix

// before
uppy.addFile({ name: 'x.png', type: 'image/png', data: null, meta: {} })
// -> thumbnail request throws 'File data is empty'

// after
uppy.addFile({
  name: 'x.png',
  type: 'image/png',
  data: new Blob([...], { type: 'image/png' }),
})
Defensive patterns

Strategy: validation

Validate before calling

const files = Object.values(uppy.getState().files)
const withData = files.filter((f) => f.data != null)
// only these are eligible for thumbnail generation

Type guard

function hasFileData(file: { data?: Blob | null }): file is { data: Blob } {
  return file.data != null
}

Try / catch

uppy.on('thumbnail:error', (file, err) => {
  if (err.message === 'File data is empty') uppy.setFilePreview(file.id, placeholderIcon)
})

Prevention

When it happens

Trigger: ThumbnailGenerator.requestThumbnail -> createThumbnail for a file whose data is null. Happens with files restored from Golden Retriever where blob recovery failed, files created via uppy.addFile with meta only and a preview but no data, or after data was deliberately cleared post-upload.

Common situations: Golden Retriever restoring file state after a crash without actual blobs; custom code calling uppy.addFile({data: null, previewURL}) to fake entries; race where thumbnails are requested after uppy.removeFile cleared data.

Related errors


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