0

i am following Using PhoneGap FileWriter.write for "big" files methode to write large file in cordova android app. but in this i can not append net mb data. result is only first 1mb data. can some one help me hoe tho sort out this

my code

   function writeFile1(fileEntry, dataObj, isAppend, content1) {

   fileEntry.createWriter(function(fileWriter) {


       function writeFinish() {

           alert("The file has written successfully.", "success");

       }



       fileWriter.onerror = function(e) {

           messagefunctioning("Failed file write: " + e.toString(), "error");
       };


       if (!dataObj) {
           dataObj = new Blob(['No db query has been retrieved. Please try again later.'], {
               type: 'text/plain'
           });
       }


       data = dataObj;

       var written = 0;
       var BLOCK_SIZE = 1 * 1024 * 1024; // write 1M every time of write
       var bytelngth = getByteLen(data);

       function writeNext(cbFinish) {
           alert("endssss");


           var sz = Math.min(BLOCK_SIZE, bytelngth - written); //alert("sz"+sz);
           //sz=5;
           var sub = data.slice(written, written + sz); //alert("sub"+sub);

           if (isAppend) { //alert("append");
               try { //alert("append try");alert(fileWriter.length);
                   fileWriter.seek(fileWriter.length);

               } catch (e) {
                   alert("file doesn't exist!");
               }
           }
           fileWriter.write(sub);

           written += sz;
           fileWriter.onwrite = function(evt) {
               if (written < bytelngth) {
                   writeNext(cbFinish);
               } else
                   cbFinish();
           };

       }
       //alert("4");
       writeNext(writeFinish);



       // fileWriter.write(dataObj);
   });

}

0 Answers0