Replace file blob in browser?

I asked this earlier but someone down voted and accused me of trying to write files to local filesystem without reading.

I have website in an enterprise environment which will only ever be accessed in chrome so keep that in mind.

  • parse file in angularjs controller before upload
  • Cordova SQLite save BLOB
  • How to pass a Blob object from javascript to Android?
  • How to create a Blob from a local file in phonegap on android
  • Display image from blob using javascript and websockets
  • How do I tell the type of websocket onmessage's parameter?
  • I am able to select a local folder on my PC and open all sub-folders and files in the browser. I’m using client side javascript to parse these files and look for a particular kind of .xml file that is used internally to render a powerpoint like presentation. I can make changes to this xml file and spit it back out as a blob.

    What I would like to do but don’t know how is replace the data or blob in the original file with the modified data/blob.

  • Blob constructor browser compatibility
  • Changing blob url to download link
  • Blob URL to image
  • How to stream video data to a video element?
  • Setting autorevoke for URL.createObjectURL
  • How to use Blob in safari 5.1
  • One Solution collect form web for “Replace file blob in browser?”

    Can the user interact with the data blob? If so, you can use a save file function and overwrite the original.

    function saveFile( data )
      var textFileAsBlob = new Blob([yourData], {type:'text/plain'});
      //or replace the code above with your already formed blob
      var fileNameToSaveAs = "File_Name_Goes_Here.xml";
      var downloadLink = document.createElement("a"); = fileNameToSaveAs;
      //downloadLink.innerHTML = "Download File";
      if (window.webkitURL != null){
          // Chrome allows the link to be clicked
          // without actually adding it to the DOM.
          downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
          // Firefox requires the link to be added to the DOM
          // before it can be clicked.
          try {
              downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
              downloadLink.onclick = destroyClickedElement;
     = "none";
          catch( e ){
              console.log("error saving firefox file")
          // IE 10+
          try {
              window.navigator.msSaveBlob(textFileAsBlob, fileNameToSaveAs);
              console.log("error saving IE file")
      try {
      catch(e) {
          console.log("Unable to click the download link.  Are you using IE?")

    I grabbed this code from somewhere else on stack overflow. I can’t remember who it’s from though to provide attribution 🙁