Browse Source

Fixed

pull/15498/head
Maksym Tsymbarov 5 months ago
parent
commit
ee81d4b967
  1. 86
      ui-ngx/src/app/shared/components/file-input.component.ts

86
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<any> {
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;
}

Loading…
Cancel
Save