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> { private readerAsFile(file: flowjs.FlowFile): Promise<any> {
return new Promise((resolve) => { return new Promise((resolve) => {
if (this.readAsBinary) { if (this.workFromFileObj) {
const reader = new FileReader(); resolve({
reader.onload = () => { fileContent: null,
let fileName = null; fileName: file.name,
let fileContent = null; files: file.file,
let files = null; mediaType: file.file?.type || null
let mediaType = null; });
if (reader.readyState === reader.DONE) { return;
if (!this.workFromFileObj) { }
fileContent = reader.result;
if (fileContent && fileContent.length > 0) { const reader = new FileReader();
if (this.contentConvertFunction) { reader.onload = () => {
fileContent = this.contentConvertFunction(fileContent as string); let fileName = null;
} let fileContent = null;
fileName = fileContent ? file.name : null; let mediaType = null;
mediaType = file?.file?.type || null; if (reader.readyState === reader.DONE) {
} fileContent = reader.result;
} else if (file.name || file.file) { if (fileContent && fileContent.length > 0) {
files = file.file; if (this.contentConvertFunction) {
fileName = file.name; fileContent = this.contentConvertFunction(fileContent);
mediaType = file.file.type || null;
} }
fileName = fileContent ? file.name : null;
mediaType = file?.file?.type || null;
} }
resolve({fileContent, fileName, files, mediaType}); }
}; resolve({fileContent, fileName, files: null, mediaType});
reader.onerror = () => { };
resolve({fileContent: null, fileName: null, files: null, mediaType: null}); reader.onerror = () => {
}; resolve({fileContent: null, fileName: null, files: null, mediaType: null});
};
if (this.readAsBinary) {
reader.readAsBinaryString(file.file); reader.readAsBinaryString(file.file);
} else { } else {
if (this.workFromFileObj) {
resolve({
fileContent: null,
fileName: file.name,
files: file.file,
mediaType: file.file?.type || null
});
return;
}
file.file.arrayBuffer().then(buf => { file.file.arrayBuffer().then(buf => {
const bytes = new Uint8Array(buf); const bytes = new Uint8Array(buf);
let text: string; let text: string;
@ -252,26 +247,13 @@ export class FileInputComponent extends PageComponent implements AfterViewInit,
} catch { } catch {
text = new TextDecoder('iso-8859-1').decode(bytes); text = new TextDecoder('iso-8859-1').decode(bytes);
} }
Object.defineProperty(reader, 'readyState', {value: FileReader.DONE, configurable: true});
let fileContent: any = text && text.length > 0 ? text : null; Object.defineProperty(reader, 'result', {value: text, configurable: true});
let fileName: string = null; reader.onload(new ProgressEvent('load'));
const mediaType: string = file?.file?.type || null; }).catch(() => reader.onerror(new ProgressEvent('error')));
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});
});
} }
}); });
} }
private checkMaxSize(file: flowjs.FlowFile): boolean { private checkMaxSize(file: flowjs.FlowFile): boolean {
return !this.maxSizeByte || file.size <= this.maxSizeByte; return !this.maxSizeByte || file.size <= this.maxSizeByte;
} }

Loading…
Cancel
Save