title: Convert any type of file into Base64 using javascript if we have URL of the file reside inside client system
body: <p>How can I convert a file (png/jpg/word/excel etc) to base64 format if I have url of the file (in the browser's sandboxed <code>LocalFileSystem</code>) which is already there in client system using javascript.</p>
  
  <p>I had tried using creating canvas(image).<br>
  I also tried file control.<br>
  I don't want to use any control as we have url of the file in the sqllite db.</p>
  
  <p>I tried </p>
  
  <pre><code>function UploadAttachmentfile() {
  try {
        if(objAttachment.length &gt;0)
        {
                 var ctn = objAttachment.length;
                                for (var j = 0; j &lt; ctn; j++) {
                                var row = objAttachment[j].IMGS; \\image
                                    var fname = row.split('\\').pop().split('/').pop();
                                    alert(fname);
                                    window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, function (fs) {
                                    alert('request file system');
                                        fs.root.getDirectory("Foldername", null, function (entry) {
                                        alert('ENTRY : '+entry);
                                            entry.getFile(fname, null, function (fileEntry) {
                                                fileEntry.file(gotFile, fail);
                                            }, fail);
                                        }, fail);
                                    }, fail);
                                    function gotFile(file) {
                                        readDataUrl(file);
                                    }
  
                                    function readDataUrl(file) {
                                        var reader = new FileReader();
                                        reader.onloadend = function (evt) {
                                            alert("Read as data URL");
                                            alert("target result :"+evt.target.result);
                                        };
                                        reader.readAsDataURL(file);
                                    }
  
                                    function fail(evt) {
                                    alert('fail');
                                        alert(evt.target.error.code);
                                    }
  
  
                                }
  
                                 }
  
  }
  catch (err) {
          }
  }
  </code></pre>
  
  <p>But it always alert fail only.</p>