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.

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(file: File)

Extracts the file extension.

Parameters :
Name Type Optional Description
file File No

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.

haveValidExtensions
haveValidExtensions(files: FileList | 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 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)

Checks if files have valid size.

Parameters :
Name Type Optional Description
files FileList No

Files to check.

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 : any

The image string in base64 format.

Properties

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

results matching ""

    No results matching ""