I have this input with which i Upload a Folder:
<div class="form-group">
<input type="file" id="file" (change)="readInput($event)" webkitdirectory directory multiple >
</div>
The Folder Contains a number of different csv files. For processing the input, I have this Filereader.
readInput(fileChangeEvent: Event) {
return new Observable<any>(obs => {
const file = (fileChangeEvent.target as HTMLInputElement).files[0];
if (file) {
const fileReader = new FileReader();
fileReader.onload = e => {
obs.next({
result: fileReader.result
});
};
fileReader.readAsText(file);
}
});
}
Now, the Observable of my Filereader seems to return the content of a random file from the folder. What i'd like to do would be to save the different Files-contents in an Array so that I could access them later in the code.
What I tried was adding the result to an array in the observable:
filearray = []
readInput(fileChangeEvent: Event) {
return new Observable<any>(obs => {
const file = (fileChangeEvent.target as HTMLInputElement).files[0];
if (file) {
const fileReader = new FileReader();
fileReader.onload = e => {
obs.next({
this.filearray.push(result);
});
};
fileReader.readAsArrayBuffer(file);
}
});
}
but this resulted in the array being empty.
How could I save the files in an array? Are there easier ways to handle a folder input than the FileReader?