Home How to obtain FileReader result?
Reply: 0

How to obtain FileReader result?

user1074 Published in March 20, 2018, 3:26 pm

I am trying to read a file from my local machine. I have attached the onFileLoad function to the upload button.

I understand that this is happening asynchronously, but how do I access the contents of the file in another function?

What I mean is, after my file is loaded, I want to be able to store the results (text in the file) into a variable. I'm using React and I want to avoid using global variables.

                 var file = event.target.files[0]; 
            if (file){
                var reader = new FileReader();
                reader.onloadend = function(e) { 
                    window.contents = e.target.result;


            else { 
                alert("Failed to load file");

What I'd ideally like to do is once the file is loaded, do something like


Can someone guide me in the right direction?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.452741 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO