0

I am developing a mobile app,where i want to download a file in memory card.I have following code for this,but its not working, can anyone suggest me why??

function dwnload()
    {    alert('in1'); 
     var fname=$("#filename").val();
     alert(fname);

      document.addEventListener('deviceready',function(){
                window.requestFileSystem(LocalFileSystem.PERSISTENT,0,gotFS,fail);


      }, false);   
     function gotFS(fileSystem){

             fileSystem.root.getfile(fname + '.csv',{create: true,exclusive: false}, gotFileEntry, fail);
  alert('in gotFS');
     }
    function gotFileEntry(fileEntry){
             fileEntry.createWriter(gotFileWriter, fail);
        alert('in gotFileEntry');

    }
    function gotFileWriter(writer)
    {     alert('in gotFileWriter');
          var text_wrt=$("#filetxt").val();

          writer.write(text_wrt);
          writer.onwriteend= function(evt)
          {
             $('#status').text('File Was saved Successfully');
          }

    }
        function fail(error)
        {
             $('#status').text('File Save Error' +error.code);

        }
    }  

and my html code for getting info.from user is as followa,once i submit following form then it calls above function,is there any error in my function for file download.

<h1>Example</h1>
    <form onsubmit="return dwnload();">
    File name:<input type="text" id="filename" name="filename" placeholder="Enter Name of File" />
    <div id="status"></div>
    <p><!-- <A HREF="#" onclick="dwnload();" data-ajax="false">Local File System</A></p> -->

    File Text:<input type="text" id="filetxt" name="filetxt" placeholder="Enter Something" />
   <BR> 
    <input type="submit" name="submit" id="submit" value="submit" data-ajax="false"></>
    </form>
8
  • 1
    Did you add the File plugin? Also, you can't say "it isn't working" - you have to say HOW it isn't working. Is there an error thrown in the console for example. Nov 15, 2014 at 14:46
  • I have added File Plugin <intelxdk:plugin intelxdk:name="File" intelxdk:value="intel.xdk.file"/> and Cordova plugin <intelxdk:plugin intelxdk:name="File" intelxdk:value="org.apache.cordova.file" intelxdk:version="0.2.5"/> And its not showing any error while trying on my samsung S4
    – sarika
    Nov 17, 2014 at 4:41
  • No error- but where does it stop working? Have you stepped through the JS code? Nov 17, 2014 at 11:16
  • in function gotFS it's not giving that alert,it's stoping over there
    – sarika
    Nov 18, 2014 at 4:18
  • Function gotFS doesn't have an alert. Maybe add one before you do any more code? Also, you request 0 for the file size, maybe change that to 50 megs or some such. Nov 18, 2014 at 11:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.