File

libs/core-forms/src/lib/file-uploader-component-plugin/file-uploader-config.model.ts

Index

Properties

Properties

addFileButtonLabel (Optional)
Type string
Description

Label for the button used to add files. Defaults to "Add File" if not specified.

allowedFileTypes
Type AllowedFileType[]
Description

List of allowed file types that can be uploaded.

maxFileSize (Optional)
Type number
Description

Per-file size limit in bytes. Must be at least 100 bytes. Maximum allowed value is 10485760 (10 MB).

maxNumberOfFiles (Optional)
Type number
Description

Maximum number of files that can be uploaded. Defaults: 10 if not specified. Maximum allowed value is 20.

uploadHintText (Optional)
Type string
Description

Hint text displayed above the file uploader.

export type AllowedFileType =
  | 'pdf'
  | 'doc'
  | 'docx'
  | 'xls'
  | 'xlsx'
  | 'heic'
  | 'png'
  | 'jpg'
  | 'jpeg'
  | 'gif'
  | 'ppt'
  | 'pptx';

export interface FileUploaderConfig {
  /**
   * List of allowed file types that can be uploaded.
   */
  allowedFileTypes: AllowedFileType[];

  /**
   * Maximum number of files that can be uploaded.
   * Defaults: 10 if not specified. Maximum allowed value is 20.
   */
  maxNumberOfFiles?: number;

  /**
   * Per-file size limit in bytes.
   * Must be at least 100 bytes. Maximum allowed value is 10485760 (10 MB).
   */
  maxFileSize?: number;

  /**
   * Hint text displayed above the file uploader.
   */
  uploadHintText?: string;

  /**
   * Label for the button used to add files.
   * Defaults to "Add File" if not specified.
   */
  addFileButtonLabel?: string;
}

export const FILE_UPLOADER_ERROR_TRANSLATION_KEYS = {
  invalidExtension: 'fileUploaderErrorInvalidExtension',
  exceedsCount: 'fileUploaderErrorExceedsCount',
  belowMinSize: 'fileUploaderErrorBelowMinSize',
  exceedsMaxFileSize: 'fileUploaderErrorExceedsMaxFileSize',
  exceedsTotalSize: 'fileUploaderErrorExceedsTotalSize',
  nameTooLong: 'fileUploaderErrorNameTooLong',
  duplicate: 'fileUploaderErrorDuplicate',
  corrupted: 'fileUploaderErrorCorrupted',
  uploadFailed: 'fileUploaderErrorUploadFailed'
} as const;

export type FileUploaderErrorKey = keyof typeof FILE_UPLOADER_ERROR_TRANSLATION_KEYS;
export const FILE_UPLOADER_ERROR_KEYS = Object.keys(
  FILE_UPLOADER_ERROR_TRANSLATION_KEYS
) as FileUploaderErrorKey[];

export const FILE_UPLOADER_UI_TRANSLATION_KEYS = {
  addFileButtonLabel: 'fileUploaderAddFileButtonLabel',
  closeButtonLabel: 'fileUploaderCloseButtonLabel',
  maxFilesReachedLabel: 'fileUploaderMaxFilesReachedLabel'
} as const;

export type FileUploaderUiLabelKey = keyof typeof FILE_UPLOADER_UI_TRANSLATION_KEYS;
export const FILE_UPLOADER_UI_LABEL_KEYS = Object.keys(
  FILE_UPLOADER_UI_TRANSLATION_KEYS
) as FileUploaderUiLabelKey[];

/** Maximum combined size of all uploaded files in bytes (10 MB). */
export const MAX_TOTAL_SIZE_BYTES = 10 * 1024 * 1024;

export const MIN_FILE_SIZE_BYTES = 100;

export const MAX_FILE_NAME_LENGTH = 255;

export const MAX_FILE_COUNT = 20;

export const DEFAULT_MAX_FILE_COUNT = 10;

export const ALLOWED_FILE_TYPE_MIME_MAP: Record<AllowedFileType, string> = {
  pdf: 'application/pdf',
  doc: 'application/msword',
  docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
  xls: 'application/vnd.ms-excel',
  xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  heic: 'image/heic',
  png: 'image/png',
  jpg: 'image/jpeg',
  jpeg: 'image/jpeg',
  gif: 'image/gif',
  ppt: 'application/vnd.ms-powerpoint',
  pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation'
};

results matching ""

    No results matching ""