From ee81d4b967ccc81c4ed912de85ab741485851cfc Mon Sep 17 00:00:00 2001 From: Maksym Tsymbarov Date: Wed, 29 Apr 2026 14:28:07 +0200 Subject: [PATCH] Fixed --- .../shared/components/file-input.component.ts | 86 ++++++++----------- 1 file changed, 34 insertions(+), 52 deletions(-) diff --git a/ui-ngx/src/app/shared/components/file-input.component.ts b/ui-ngx/src/app/shared/components/file-input.component.ts index c7c977311e..51b3fec787 100644 --- a/ui-ngx/src/app/shared/components/file-input.component.ts +++ b/ui-ngx/src/app/shared/components/file-input.component.ts @@ -205,45 +205,40 @@ export class FileInputComponent extends PageComponent implements AfterViewInit, private readerAsFile(file: flowjs.FlowFile): Promise { return new Promise((resolve) => { - if (this.readAsBinary) { - const reader = new FileReader(); - reader.onload = () => { - let fileName = null; - let fileContent = null; - let files = null; - let mediaType = null; - if (reader.readyState === reader.DONE) { - if (!this.workFromFileObj) { - fileContent = reader.result; - if (fileContent && fileContent.length > 0) { - if (this.contentConvertFunction) { - fileContent = this.contentConvertFunction(fileContent as string); - } - fileName = fileContent ? file.name : null; - mediaType = file?.file?.type || null; - } - } else if (file.name || file.file) { - files = file.file; - fileName = file.name; - mediaType = file.file.type || null; + if (this.workFromFileObj) { + resolve({ + fileContent: null, + fileName: file.name, + files: file.file, + mediaType: file.file?.type || null + }); + return; + } + + const reader = new FileReader(); + reader.onload = () => { + let fileName = null; + let fileContent = null; + let mediaType = null; + if (reader.readyState === reader.DONE) { + fileContent = reader.result; + if (fileContent && fileContent.length > 0) { + if (this.contentConvertFunction) { + fileContent = this.contentConvertFunction(fileContent); } + fileName = fileContent ? file.name : null; + mediaType = file?.file?.type || null; } - resolve({fileContent, fileName, files, mediaType}); - }; - reader.onerror = () => { - resolve({fileContent: null, fileName: null, files: null, mediaType: null}); - }; + } + resolve({fileContent, fileName, files: null, mediaType}); + }; + reader.onerror = () => { + resolve({fileContent: null, fileName: null, files: null, mediaType: null}); + }; + + if (this.readAsBinary) { reader.readAsBinaryString(file.file); } else { - if (this.workFromFileObj) { - resolve({ - fileContent: null, - fileName: file.name, - files: file.file, - mediaType: file.file?.type || null - }); - return; - } file.file.arrayBuffer().then(buf => { const bytes = new Uint8Array(buf); let text: string; @@ -252,26 +247,13 @@ export class FileInputComponent extends PageComponent implements AfterViewInit, } catch { text = new TextDecoder('iso-8859-1').decode(bytes); } - - let fileContent: any = text && text.length > 0 ? text : null; - let fileName: string = null; - const mediaType: string = file?.file?.type || null; - - if (fileContent) { - if (this.contentConvertFunction) { - fileContent = this.contentConvertFunction(fileContent); - } - fileName = fileContent ? file.name : null; - } - - resolve({fileContent, fileName, files: null, mediaType}); - }).catch(() => { - resolve({fileContent: null, fileName: null, files: null, mediaType: null}); - }); + Object.defineProperty(reader, 'readyState', {value: FileReader.DONE, configurable: true}); + Object.defineProperty(reader, 'result', {value: text, configurable: true}); + reader.onload(new ProgressEvent('load')); + }).catch(() => reader.onerror(new ProgressEvent('error'))); } }); } - private checkMaxSize(file: flowjs.FlowFile): boolean { return !this.maxSizeByte || file.size <= this.maxSizeByte; }