bergben / ng2-file-input

Angular 2 component that implements a drag and drop or select file selection, including preview.
MIT License
25 stars 11 forks source link

Show file content in text area #5

Closed ketimaBU closed 7 years ago

ketimaBU commented 7 years ago

Hi it is not an issue i m havin a struggle I am trying to load a file using ng2-file-input using following line : <ng2-file-input (onChange)="onFileChange($event)"></ng2-file-input> and in the component i am using :

public onFileChange(event: any)
   {
 console.log("the file has changed:", event);   
 console.log('This is file' + JSON.stringify(event, null, 4)+JSON.stringify(event.file, null, 4));
    }

I want to know if there is any way to get the file content so i can show it in text area

bergben commented 7 years ago

Hey there,

assuming that the user can only select .txt, .json etc. files, in order to show the contents of a file in a text area you'll have to read the contents of a file somehow like this: https://stackoverflow.com/questions/750032/reading-file-contents-on-the-client-side-in-javascript-in-various-browsers