Uplo
Analyzers

About analyzers

Analyzers are used to get information about the blob and store it to metadata. For example, you can get Image width and height with an image analyzer.

Usage

Usually you want to run these in delayed jobs to avoid blocking requests. For example, you can add afterAttach callback to Uplo and schedule a blob analyze job.

const uplo = createUplo({
  callbacks: {
    afterAttach: async ({ blob }) => {
      await DelayedJob.performLater('uplo-analyze-blob', { id: blob.id })
    },
  },
})

Then, in the delayed job you can find blob and call analyze like this:

import { createAnalyzer } from '@uplo/analyzer'
import { imageAnalyzer } from '@uplo/analyzer-image'
import { uplo } from './lib/uplo'

const analyzer = createAnalyzer({
  analyzers: [imageAnalyzer()],
})

export const uploAnalyzeBlobWorker = async ({ id }: { id: ID }) => {
  if (!id) return

  const blob = await uplo.$findBlob(id)
  if (!blob) return

  return await analyzer.analyze({ blob })
}

On this page