Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

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

Options
  • 21-03-2015 1: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