ChatiumFor developersPlaygroundPricing
Sign in

StorageImageFile

A wrapper class for convenient handling of hash identifiers for video files uploaded to a media storage.

Instances of the StorageVideoFile class represent runtime values of fields in heap tables declared through Heap.VideoFile and Heap.File (only for video files).

It can also be used for convenient handling of uploaded image files outside the context of the heap.

Usage/Signature

import { StorageVideoFile } from '@app/storage'
const file = new StorageVideoFile(hash)

Properties and Methods

All properties of the base class StorageFile (only type always returns video) + ...

videoSrc: Promise<{ mp4?, hls?, width?, height? }>
Returns an object with absolute URLs and dimensions of the video stream in a format accepted by the src property of the video block.

getThumbnailUrl(width?: number, height?: number, offsetSeconds?: 'auto' | number): string

  • Returns an absolute URL of a frame image from the video stream considering the specified dimensions and time offset.

    • If both dimensions are not specified, the original size of the video stream is used.

    • If one of the dimensions is specified, the other is automatically adjusted according to the original aspect ratio.

    • If both dimensions are specified, the thumbnail is cropped according to the "cover" rule - the image is cropped from both sides either vertically or horizontally depending on the proportions.

  • width: number | undefined
    The required width of the thumbnail in pixels.

  • height: number | undefined
    The required height of the thumbnail in pixels.

  • offsetSeconds: 'auto' | number | undefined
    The frame offset in seconds from the start of the video, supports fractional values.

getThumbnailSrc(width?: number, height?: number, offsetSeconds?: 'auto' | number): { url, width?, height? }

  • Returns an object with absolute URL and dimensions of the thumbnail image in a format accepted by the src property of the video block considering the specified dimensions.

    • If both dimensions are not specified, the original size of the image is used.

    • If one of the dimensions is specified, the other is automatically adjusted according to the original aspect ratio.

    • If both dimensions are specified, the thumbnail is cropped according to the "cover" rule - the image is cropped from both sides either vertically or horizontally depending on the proportions.

  • width: number | undefined
    The required width of the thumbnail in pixels.

  • height: number | undefined
    The required height of the thumbnail in pixels.

  • offsetSeconds: 'auto' | number | undefined
    The frame offset in seconds from the start of the video, supports fractional values.

width: number
"The strict" width of the image in pixels, determined from the hash property. If for any reason the width cannot be determined, an appropriate exception will be be thrown upon access.

widthMaybe: number | undefined
"The non-strict" width of the image in pixels, determined from the hash property. Returns undefined if for any reason the width cannot be determined.

height: number
"The strict" height of the image in pixels, determined from the hash property. If for any reason the height cannot be determined, an appropriate exception will be thrown upon access.

heightMaybe: number | undefined
"The non-strict" height of the image in pixels, determined from the hash property. Returns undefined if for any reason the height cannot be determined.

sizes: { width: number, height: number }
"The strict" dimensions of the image in pixels, determined from the hash property. If for any reason the dimensions cannot be determined, an appropriate exception will be thrown upon access.

sizesMaybe: { width: number, height: number } | undefined
"The non-strict" dimensions of the image in pixels, determined from the hash property. Returns undefined if for any reason the dimensions cannot be determined.

duration: number
"The strict" length of the video in seconds, determined from the hash property. If for any reason the length cannot be determined, an appropriate exception will be thrown upon access.

durationMaybe: number | undefined
"The non-strict" length of the video in seconds, determined from the hash property. Returns undefined if for any reason the length cannot be determined.

status: Promise<'done' | 'processing' | 'error'>\

  • The current status of video processing.

  • Video files do not become available for download immediately after upload, as they undergo a special encoding process in storage.

    • done — the file is ready, it can be used.
    • processing — the file is being encoded, the current progress can be checked from the progress property.
    • error — an error occurred during encoding, likely due to an incompatible file format.

progress: Promise<number>
A number from 0 to 100 indicating the current percentage of completion of the encoding process when status=processing.