How to read contents of files with Angular 5?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



How to read contents of files with Angular 5?



i want to read the contents of different files which is taken from input type file



This is my html code:


<input id="input-file" type="file" name="file" (change)="onFileSelected($event)" accept="application/pdf;image/jpeg;image/gif;image/tif;image/tiff;image/jpg;image/png;application/vnd.openxmlformats-officedocument.presentationml.presentation"/>



This is type script code :


onFileSelected(event)
if(event.target.files.length > 0)
var reader = new FileReader();
reader.onload = () =>
console.log(reader.result);
;





1 Answer
1



You must read the file (i.e by calling readAsText for a text file) before logging the result.


readAsText


var reader = new FileReader();

reader.onload = function(e)
var text = reader.result;
console.log(text );

reader.readAsText(file, encoding);



By your requirement and the type file, there are a lot of methods available for you



readAsDataURL : for the image i.e



readAsBinaryString






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

make 2 or more post in bootsrap

Store custom data using WC_Cart add_to_cart() method in Woocommerce 3

Firebase Auth - with Email and Password - Check user already registered