FileUtils: {
    bytesToSize(bytes): string;
    downloadBlob(blob, filename): void;
    extractBase64FromLocalUrl(url): string;
    fileIsAlreadyAttached(file, files): undefined | FileData;
    getBasicFileType(file): FileType;
    getImagePreview(file): Promise<string>;
    getLocalUrl(file, callback): void;
    isFileExtension(extension): boolean;
    sizeToBytes(size, units): number;
} = ...

Utility object containing file handling functions.

Type declaration

  • bytesToSize:function
    • Converts bytes to a human-readable size string.

      Parameters

      • bytes: number

        Number of bytes to convert

      Returns string

      Formatted size string (e.g., "1.5 MB")

      Example

      const size = FileUtils.bytesToSize(1500000); // "1.5 MB"
      
  • downloadBlob:function
    • Downloads a blob as a file. Supports both modern browsers and IE.

      Parameters

      • blob: Blob

        Blob to download

      • filename: string

        Name of the file to save as

      Returns void

      Example

      const blob = new Blob(['Hello World'], { type: 'text/plain' });
      FileUtils.downloadBlob(blob, 'hello.txt');
  • extractBase64FromLocalUrl:function
    • Extracts base64 data from a local URL.

      Parameters

      • url: string

        URL containing base64 data

      Returns string

      Base64 string or original URL if no base64 data found

      Example

      const base64 = FileUtils.extractBase64FromLocalUrl('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...');
      
  • fileIsAlreadyAttached:function
    • Checks if a file is already attached to a list of files.

      Parameters

      Returns undefined | FileData

      The matching file if found, undefined otherwise

      Example

      const isDuplicate = FileUtils.fileIsAlreadyAttached(newFile, existingFiles);
      
  • getBasicFileType:function
    • Gets the basic file type (image, video, audio, or document).

      Parameters

      • file: File

        File to check

      Returns FileType

      Basic file type

      Example

      const type = FileUtils.getBasicFileType(imageFile); // "image"
      
  • getImagePreview:function
    • Gets a base64 preview of an image file.

      Parameters

      • file: File

        Image file to preview

      Returns Promise<string>

      Promise resolving to base64 string of the image

      Throws

      Error if file is not an image or fails to load

      Example

      const preview = await FileUtils.getImagePreview(imageFile);
      
  • getLocalUrl:function
    • Gets a local URL for a file.

      Parameters

      • file: File

        File to get URL for

      • callback: ((url) => void)

        Callback function to receive the URL

          • (url): void
          • Parameters

            • url: string

            Returns void

      Returns void

      Example

      FileUtils.getLocalUrl(file, (url) => {
      console.log('File URL:', url);
      });
  • isFileExtension:function
    • Checks if a value is a valid file extension.

      Parameters

      • extension: string

        File extension to validate

      Returns boolean

      True if valid, false otherwise

      Example

      const isValid = FileUtils.isFileExtension('jpg'); // true
      
  • sizeToBytes:function
    • Converts a size with units to bytes.

      Parameters

      • size: string | number

        Size to convert

      • units: string

        Units of the size (B, KB, MB, GB, TB)

      Returns number

      Size in bytes

      Example

      const bytes = FileUtils.sizeToBytes(1.5, 'MB'); // 1572864