Link to home
Start Free TrialLog in
Avatar of tonelm54
tonelm54

asked on

Get input file to blob

Im working on an offline application, is there a way I can get the element:-
<input type="file" id="fliBlob" />

Open in new window

and get the blob data in base64 for it so I can store it in a LocalStorage for upload later? Im assuming I will also need to get the filename if possible.

Any ideas?
Avatar of tonelm54
tonelm54

ASKER

Ive written the following, which Ive tried to run as 'getDataFile("myInput")' however when it runs, I just get undefined returned
      function getDataFile(inputFile) {
         var fileInput = document.getElementById(inputFile);


         var reader = new FileReader();
         var retData;
         reader.readAsDataURL(fileInput.files[0]);


         reader.onload = function () {
            retData = reader.result;//base64encoded string
         };
         reader.onerror = function (error) {
            console.log('Error: ', error);
         };
         return retData;
      }

Open in new window

Any ideas what Ive done wrong to get the blob data?

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial