Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Cordova Android app, file_not_found when trying to upload to remote server

  • 21-03-2015 01:21PM
    #1
    Closed Accounts Posts: 3,596 ✭✭✭


    I am trying to upload a file to a remote server using a Cordova Android application, I can resolve the URL of the file path and it I can print the path of the file so it definitely can find the file and it does exist. But whenever I go to upload the file it keeps failing with an error code of 1 which means the file was not found. The file is located on my sd card and I create it using the app. Here is my code for uploading the file.
    function upload()
     {
        
    
        window.resolveLocalFileSystemURL("file:///storage/emulated/0/testFile5.txt", gotFileAddress, error);
     } 
    
    
    function error() 
      { 
         alert("no file");
      }
    
    
    
    function gotFileAddress(fileEntry) 
      {
       
        fileURL = fileEntry.toURL();
        server =  encodeURI("http://example.server.com/upload");
        alert(fileURL)
    
        var options = new FileUploadOptions();
        options.fileKey = "file";
        options.fileName = fileURL.substr(fileURL.lastIndexOf('/') + 1);
        options.mimeType = "text/plain";
    
        alert("a"+ options.fileName );
    
        var ft = new FileTransfer();
        ft.upload(fileURL,server, win, fail, options);
    
        alert("d");
    
         function win(r)
            {
            console.log("Code = " + r.responseCode);
            console.log("Response = " + r.response);
            console.log("Sent = " + r.bytesSent);
            }
    
        function fail (error) 
            {
            alert("An error has occurred: Code = " + error.code);
            alert("upload error source " + error.source +  " \n upload error target " + error.target);
            }
    }// end of upload
    


    Has anyone any suggestions ? I have been stuck on this for ages


Advertisement