title: IONIC3 - WriteFile & WriteExistingFile is unable to overwrite the file
body: <p>I would like to do image annotation for my Ionic Application. So the flow of the app would be using the camera plugin to take a picture and use FabricJs to draw on the image then save the file.</p>
  
  <p>I hit the roadblock when I am trying to save or overwrite the file. Apparently the source "<a href="http://localhost:8080/_file_/data/user/0/" rel="nofollow noreferrer">http://localhost:8080/<em>file</em>/data/user/0/</a>***/files/1547183479807.png" file does not update.</p>
  
  <p>The flow of the app
  1) Take picture with @ionic-native/camera
  2) Copy the file to a local directory
  3) Use this.win.Ionic.WebView.convertFileSrc to convert the file name to "<a href="http://localhost:8080/_file_/data/user/0/" rel="nofollow noreferrer">http://localhost:8080/<em>file</em>/data/user/0/</a>***/files/1547183479807.png"
  4) Push to another page to access the canvas
  5) Use the link to setBackground to my canvas (FabricJs)
  6) Draw on the image (Manually)
  7) Save the file via overwriting the existing file but nothing works from here on.</p>
  
  <p>I tried to 
  - overwrite with writeFile &amp; writeExisitingFile, did not work.
  - removeFile and writeFile and did not work.
  - tried converting to ArrayBuffer rather than Blob and did not work
  - tried creating another new file, did not work too (it seems like after I push to a new page, all the file functions does not affect the files)
  - tried using native cordova but did not work too.
  - delete that same files twice, (first time I did not get an error but the second time I got an error saying "File Does not exist" but when I view the source, the file is also there and appearing in my thumbnail on my App.</p>
  
  <pre><code>private copyFileToLocalDir(namePath, currentName, newFileName,id,index) {
  this.file.copyFile(namePath, currentName, this.file.dataDirectory, newFileName).then(success =&gt; {
    const keys = id.split('-');
    let filename = this.file.dataDirectory + newFileName;
    this.fp = this.win.Ionic.WebView.convertFileSrc(filename) ;
    this.navCtrl.push(AnnotationsPage, {
      filepath: this.fp,
      filename: newFileName
    });
     this.presentToast("Image Successfully Added",'middle');
  }, error =&gt; {
    this.presentToast('Error while storing file.','middle');
  });
  } 
  </code></pre>
  
  <p>Annotation.ts</p>
  
  <pre><code>savePicture() {
  let image = this.canvas.toDataURL({
    format: 'png'
  });
  this.saveBase64(image);
  }
  
  public saveBase64(base64:string):Promise&lt;string&gt;{
  return new Promise((resolve, reject)=&gt;{
    var realData = base64.split(",")[1]
    let blob=this.b64toBlob(realData,"image/png")
      this.file.writeFile(this.file.dataDirectory,this.filename,blob,{replace:true})
      // this.file.writeExistingFile(this.file.dataDirectory,this.filename, blob)
        .then((val)=&gt;{
          console.log('Write Info',val)
          let fp = this.win.Ionic.WebView.convertFileSrc(this.file.dataDirectory+this.filename) ;
  
        })
        .catch((err)=&gt;{
          console.log('error writing blob')
          console.log(err);
          // reject(err)
        })
  
  })
  }
  
  b64toBlob(b64Data, contentType) {
  contentType = contentType || '';
  var sliceSize = 512;
  var byteCharacters = atob(b64Data);
  var byteArrays = [];
  
  for (var offset = 0; offset &lt; byteCharacters.length; offset += sliceSize) {
    var slice = byteCharacters.slice(offset, offset + sliceSize);
  
    var byteNumbers = new Array(slice.length);
    for (var i = 0; i &lt; slice.length; i++) {
      byteNumbers[i] = slice.charCodeAt(i);
    }
  
    var byteArray = new Uint8Array(byteNumbers);
  
    byteArrays.push(byteArray);
  }
  </code></pre>
  
  <p>I check the base64 file, it is working fine (Throw the data to an online converter and it display the picture.</p>
  
  <p>After the function "copyFileToLocalDir", it seems like I am unable to modify the files store in the local directory.</p>
  
  <p>Thanks in advance. Feel free to ask me more question. 7 hours and no result.</p>
  
  <p><strong>Update on the testing, I am doing.
  Did File.readAsDataUrl and as expected the file file:///data/user/0/*</strong>/files/1547231914843.png updated from the old image to the new edited. (Tested the base64 on some online converter) but it still does not reflect on the source <a href="http://localhost:8080/_file_/data/user/0/" rel="nofollow noreferrer">http://localhost:8080/<em>file</em>/data/user/0/</a>***/files/1547231914843.png</p>