File

core/common/files.service.ts

Index

Properties
Methods

Constructor

constructor(systemOptionsService: SystemOptionsService, inventoryBinaryService: InventoryBinaryService)
Parameters :
Name Type Optional
systemOptionsService SystemOptionsService No
inventoryBinaryService InventoryBinaryService No

Methods

checkMaxLength
checkMaxLength(files: FileList)

Checks if each file has a valid filename length.

Parameters :
Name Type Optional Description
files FileList No

Files to check.

Returns : boolean

Returns true if each file has a valid filename length.

Async download
download(binary: IManagedObjectBinary)

Allows to download a file (opens the browser download prompt).

Parameters :
Name Type Optional Description
binary IManagedObjectBinary No

The binary managed object.

Returns : any
extractFileExtensions
extractFileExtensions(str: string)

Extracts a list of file extensions from a string. Can accept generic file types check: GENERIC_FILE_TYPE.

Accepted string format:

  • ".zip,.iso",
  • "zip,ISO",
  • "archive". Important: generic types cannot contain a dot. All values with a dot are treated as a normal extension.
Parameters :
Name Type Optional Description
str string No

String from which the file extensions are extracted (comma separated values). Accepted string format:

  • ".zip,.iso",
  • "zip,ISO",
  • "archive". Important: generic types cannot contain a dot. All values with a dot are treated as a normal extension.
Returns : string[]

Returns a list of the file extensions.

fetchFileWithProgress$
fetchFileWithProgress$(binary: IManagedObjectBinary)

Loads the file to JavaScript memory. Returns an observable that emits progression status object, and after download is completed, blob property is populated with Blob result object. Unsubscribing from the returned observable aborts the file fetch request.

Parameters :
Name Type Optional Description
binary IManagedObjectBinary No

The binary managed object.

fileNamesHaveValidExtension
fileNamesHaveValidExtension(fileNames: string | string[], accept: string)

Checks if file names have allowed extension. If the accept parameter is not specified, all extensions are accepted.

Parameters :
Name Type Optional Description
fileNames string | string[] No

The file names to check.

accept string No

String of comma separated file extensions and generic types (GENERIC_FILE_TYPE), e.g. .zip,.7z,excel.

Returns : boolean

Returns true if each file has allowed extension.

Async getFile
getFile(binary: IManagedObjectBinary)

Allows to get a File representation of an managed object binary. Can be used to convert this file toBase64 to show it to the end-user.

Parameters :
Name Type Optional Description
binary IManagedObjectBinary No

The binary managed object

Returns : Promise<File>

The file representation.

getFileExtension
getFileExtension(fileOrFileName: File | string)

Extracts the file extension.

Parameters :
Name Type Optional Description
fileOrFileName File | string No

File or name of file from which the extension should be extracted.

Returns : string | undefined

Returns the file extension or undefined if the file has no extension.

getFileExtensions
getFileExtensions()

List of file extensions.

Returns : string[]

Returns list of file extensions.

getGenericFileTypes
getGenericFileTypes()

The list of generic file types.

Returns the list of generic file types.

Async getHashSumOfFile
getHashSumOfFile(file: File | Blob)

Allows to calculate the hash sum of the provided file.

Parameters :
Name Type Optional Description
file File | Blob No

The file to hash.

Returns : Promise<string>

The SHA-256 hash of the file.

haveValidExtensions
haveValidExtensions(files: FileList | File | File[], accept: string)

Checks whether files have allowed extensions. If the accept parameter is not specified, all extensions are accepted.

Parameters :
Name Type Optional Description
files FileList | File | File[] No

Files to check.

accept string No

String of comma separated file extensions and generic types (GENERIC_FILE_TYPE), e.g. .zip,.7z,excel.

Returns : boolean

Returns true if each file has allowed extension.

Async haveValidSizes
haveValidSizes(files: FileList, maxFileSizeInBytes?: number)

Checks if files have valid size.

Parameters :
Name Type Optional Description
files FileList No

Files to check.

maxFileSizeInBytes number Yes
Returns : Promise<boolean>

Returns true if each file has the correct size.

Async loadBytesSizeLimit
loadBytesSizeLimit()

Checks the system file size limit, if not available returns the default value. Default limit: DEFAULT_BYTES_LIMIT

Returns : Promise<number>

Returns promise with the limit value.

size
size(file: File | IManagedObjectBinary)

Checks the size of the file

Parameters :
Name Type Optional Description
file File | IManagedObjectBinary No

File to check.

Returns : number

Returns size of the file in bytes.

toBase64
toBase64(file: File)

Converts a file to a base64 image string.

Parameters :
Name Type Optional Description
file File No

The file to convert to base 64.

Returns : Promise<string>

The image string in base64 format.

uploadFileWithProgress$
uploadFileWithProgress$(file: Stream | Buffer | File | Blob)
Parameters :
Name Type Optional
file Stream | Buffer | File | Blob No

Properties

Readonly DEFAULT_BYTES_LIMIT
Type : number
Default value : 52428800
Readonly FILENAME_MAX_LENGTH
Type : number
Default value : 128
fileTypeExtensionsMap
Default value : { [GENERIC_FILE_TYPE.ARCHIVE]: { exts: ['7z', 'apk', 'cab', 'gz', 'iso', 'jar', 'rar', 'tar', 'zip'] as const }, [GENERIC_FILE_TYPE.AUDIO]: { exts: [ '3gp', 'aiff', 'aac', 'amr', 'm4a', 'm4p', 'mp3', 'oga', 'ogg', 'raw', 'wav', 'wma' ] as const }, [GENERIC_FILE_TYPE.CODE]: { exts: ['aspx', 'exe', 'htm', 'html', 'jad', 'js', 'json', 'jsp', 'php', 'xml'] as const }, [GENERIC_FILE_TYPE.EXCEL]: { exts: ['xls', 'xlsx'] as const }, [GENERIC_FILE_TYPE.IMAGE]: { exts: ['bmp', 'gif', 'jpeg', 'jpg', 'png', 'tiff', 'svg', 'ico', 'apng', 'webp'] as const }, [GENERIC_FILE_TYPE.PDF]: { exts: ['pdf'] as const }, [GENERIC_FILE_TYPE.POWERPOINT]: { exts: ['ppt', 'pptx'] as const }, [GENERIC_FILE_TYPE.TEXT]: { exts: ['txt'] as const }, [GENERIC_FILE_TYPE.VIDEO]: { exts: ['asf', 'avi', 'flv', 'mov', 'mp4', 'ogv', 'qt', 'rm', 'rmvb', 'wmv', '3gp'] as const }, [GENERIC_FILE_TYPE.WORD]: { exts: ['doc', 'docx'] as const }, [GENERIC_FILE_TYPE.EPL]: { exts: ['mon'] as const } } as const satisfies { [key: string]: { exts: ReadonlyArray<string> } }

results matching ""

    No results matching ""