core/common/files.service.ts
Properties |
|
Methods |
constructor(systemOptionsService: SystemOptionsService, inventoryBinaryService: InventoryBinaryService)
|
|||||||||
Parameters :
|
checkMaxLength | ||||||||
checkMaxLength(files: FileList)
|
||||||||
Checks if each file has a valid filename length.
Parameters :
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 :
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:
Parameters :
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 :
Returns :
Observable<IFetchWithProgress>
|
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 :
Returns :
boolean
Returns true if each file has allowed extension. |
getFileExtension | ||||||||
getFileExtension(fileOrFileName: File | string)
|
||||||||
Extracts the file extension.
Parameters :
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 :
GENERIC_FILE_TYPE[]
Returns the list of generic file types. |
Async getHashSumOfFile | ||||||||
getHashSumOfFile(file: File | Blob)
|
||||||||
Allows to calculate the hash sum of the provided file.
Parameters :
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 :
Returns :
boolean
Returns true if each file has allowed extension. |
Async haveValidSizes | ||||||||||||
haveValidSizes(files: FileList, maxFileSizeInBytes?: number)
|
||||||||||||
Checks if files have valid size.
Parameters :
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 :
Returns :
number
Returns size of the file in bytes. |
toBase64 | ||||||||
toBase64(file: File)
|
||||||||
Converts a file to a base64 image string.
Parameters :
Returns :
Promise<string>
The image string in base64 format. |
uploadFileWithProgress$ | ||||||
uploadFileWithProgress$(file: Stream | Buffer | File | Blob)
|
||||||
Parameters :
Returns :
Observable<IFetchWithProgress>
|
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> } }
|