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 = Uplo({
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 { UploAnalyzer } from '@uplo/analyzer'
import ImageAnalyzer from '@uplo/analyzer-image';
import { uplo } from './lib/uplo'
const analyzer = UploAnalyzer({
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 });
};