Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-14197

createFile/writeFile does not consistently execute the 'write' action resulting in files of size 0

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: cordova-plugin-file
    • Labels:
      None

      Description

      Occasionally when calling the createFile API the write action does not get called. It was not very consistent though and it is very hard to reproduce. It seems as though the onload event was not firing on the fileReader in the write method resulting in the file never getting written and no callbacks being fired.

      if (data instanceof File || (!isProxySupportBlobNatively && supportsBinary && data instanceof Blob)) {
         var fileReader=new FileReader();
         /* eslint-enable no-undef */
         fileReader.onload=function () {
         // Call this method again, with the arraybuffer as argument
            FileWriter.prototype.write.call(that, this.result, true/* isPendingBlobReadResult */);
         };
         ...
      }
      

      We found we would notice the issue more consistently when running the app in the Android emulator subsequent times in a row with the command:

      $ cordova run android

      We fixed this by requiring the FileReader module:
      https://github.com/suitespot/cordova-plugin-file/commit/2a0da7f1a43e88b801ee70a3462c3df829f4c927

      With this change we have not noticed the issue anymore.

      I also believe this ionic-native issue is related to this:
      https://github.com/ionic-team/ionic-native/issues/2067#issuecomment-403600570
       
       

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                wfairclough Will Fairclough
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: