title: Cordova-Android-Camera: How to save base64 encoded jpg to Android file system
body: <p>I am succesfully creating directories, if necessary, where I want to in the Android file system on my device, a Moto X 1st gen. I am successfully saving a plain text file, but can not save a jpg file. I have the base64 encoded string of an image and it is displaying in my img tag with src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQ...". On line 17 below, I write to a file the string with "data:image/jpeg;base64," replaced with "" (empty string). Is there a conversion to binary or something I need to do before  write the file? I open the file that is written with the code snippet below in notepad++ and I see the very long base64 encoded string. Any help will be appreciated. Sorry I couldn't provide the entire code, as it is very large. I know my code works to write files, but the image file isn't writing correctly. Thanks!</p>
  
  <pre><code>var wpt = '01';
  imageName = wpt + imageName;
  var geoJSON = '{"type":"FeatureCollection","crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:EPSG::3857"}},"features":[{"type":"Feature","properties":{"TYPE":"WAYPOINT","IDENT":"null","LAT":' + latitude + ',"LONG":' + longitude + ',"Y_PROJ":null,"X_PROJ":null,"COMMENT":"' + createDate + ' ' + createTime + '","DISPLAY":"null","SYMBOL":"null","UNUSED1":"null","DIST":null,"PROX_INDEX":"null","COLOR":"null","ALTITUDE":null,"DEPTH":null,"TEMP":null,"TIME":"null","WPT_CLASS":"null","SUB_CLASS":null,"ATTRIB":"null","LINK":null,"STATE":null,"COUNTRY":null,"CITY":null,"ADDRESS":null,"FACILITY":null,"CROSSROAD":null,"UNUSED2":"null","ETE":"null","DTYPE":"null","MODEL":"SUNSAIL","FILENAME":"' + description + '","LTIME":"null","WPT":"' + wpt + '"},"geometry":{"type":"Point","coordinates":[' + coordinates + ']}}]}';
  root.getFile(gisPath + '/' + gisName, { create: true, exclusive: false}, function(fileEntry) {
      fileEntry.createWriter(function(writer) {
          writer.onwriteend = function(evt) {
              root.getFile(photoPath + '/' + imageName, { create: true, exclusive: false}, function(fileEntry) {
                  fileEntry.createWriter(function(writer) {
                      writer.onwriteend = function(evt) {
                          if (i == (numImages - 1)) {
                              alert('Waypoint data and images saved succesfully for later upload.');
                              clearCache();
                              clearNew();
                              $('.uploader').remove();
                          }
                      }
                      writer.write(img.src.replace(/data:image\/jpeg;base64,/, ''));
                  }, function(evt) {
                      alert('Error code: ' + evt.target.error.code + '\n' + 'Error message: ' + evt.target.error.message);
                  });
              }, function(evt) {
                  alert('Error code: ' + evt.target.error.code + '\n' + 'Error message: ' + evt.target.error.message);
              });
          }
          writer.write(geoJSON);
      }, function(evt) {
          alert('Error code: ' + evt.target.error.code + '\n' + 'Error message: ' + evt.target.error.message);
      });
  }, function (evt) {
      alert('Error code: ' + evt.target.error.code + '\n' + 'Error message: ' + evt.target.error.message);
  });
  </code></pre>