From 409ae412fc1b6af7fb9986bf786d35052273ba67 Mon Sep 17 00:00:00 2001 From: Artem Dzhereleiko Date: Tue, 6 Sep 2022 10:53:25 +0300 Subject: [PATCH 1/2] UI: Fixed file input --- .../shared/components/file-input.component.ts | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 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 ad2fd9f65e..c9f46d937c 100644 --- a/ui-ngx/src/app/shared/components/file-input.component.ts +++ b/ui-ngx/src/app/shared/components/file-input.component.ts @@ -188,20 +188,19 @@ export class FileInputComponent extends PageComponent implements AfterViewInit, let fileName = null; let fileContent = null; let files = null; - if (typeof reader.result === 'string') { - fileContent = reader.result; - if (fileContent && fileContent.length > 0) { - if (!this.workFromFileObj) { - if (this.contentConvertFunction) { - fileContent = this.contentConvertFunction(fileContent); - } - if (fileContent) { + if (reader.readyState === reader.DONE) { + if (!this.workFromFileObj) { + fileContent = reader.result; + if (fileContent && fileContent.length > 0) { + if (this.contentConvertFunction) { + fileContent = this.contentConvertFunction(fileContent); + } fileName = file.name; - } - } else { - files = file.file; - fileName = file.name; + files = file.file; } + } else if (file.name || file.file){ + files = file.file; + fileName = file.name; } } resolve({fileContent, fileName, files}); From a31e68cdc467286e4b1ebbcc711eae7e48d7c5b5 Mon Sep 17 00:00:00 2001 From: Artem Dzhereleiko Date: Tue, 6 Sep 2022 11:49:51 +0300 Subject: [PATCH 2/2] UI: Refactoring --- ui-ngx/src/app/shared/components/file-input.component.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 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 c9f46d937c..deee44596c 100644 --- a/ui-ngx/src/app/shared/components/file-input.component.ts +++ b/ui-ngx/src/app/shared/components/file-input.component.ts @@ -192,11 +192,10 @@ export class FileInputComponent extends PageComponent implements AfterViewInit, if (!this.workFromFileObj) { fileContent = reader.result; if (fileContent && fileContent.length > 0) { - if (this.contentConvertFunction) { - fileContent = this.contentConvertFunction(fileContent); - } - fileName = file.name; - files = file.file; + if (this.contentConvertFunction) { + fileContent = this.contentConvertFunction(fileContent); + } + fileName = fileContent ? file.name : null; } } else if (file.name || file.file){ files = file.file;