Skip to content
This repository was archived by the owner on Apr 11, 2022. It is now read-only.
This repository was archived by the owner on Apr 11, 2022. It is now read-only.

Problem with PhoneGap 5.3.9 CLI and Pluging File and File-Tranfer #586

@fabpin

Description

@fabpin

i'm running the Phonegap-CLI on a Ubuntu Gnome 64 bits with Phonegap Version 5.3.9, cordova 6.0.0, Node 4.4.1 and the Following Plugins:

`>sudo phonegap pluging list

cordova-plugin-file 4.1.1 "File"
cordova-plugin-file-transfer 1.5.0 "File Transfer"
cordova-plugin-whitelist 1.2.1 "Whitelist" `

Already had the following issue, when use File tranfer for download a FIle from my Web service , The file tranfer started to downloaded at cordova.file.dataDirectory ("Reference from readme.md of the pluging: cordova.file.dataDirectory - Persistent and private data storage within the application's sandbox using internal memory "), and stored on the following directory of my app "file:///data/data/com.adobe.phonegap.app/files/" but when i tried retrieve that document from the sandbox on that URI (Press the Button "Comprobacion" at index), the phonegap cli said me than that document didnt appear on that URI, plss help.

This is the index.html

<html>
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="msapplication-tap-highlight" content="no" />
        <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <!-- <meta http-equiv="Content-Security-Policy" content="default-src *;img-src *;script-src 'self' 'unsafe-inline' 'unsafe-eval' *; style-src  'self' 'unsafe-inline' *"> -->
        <meta http-equiv="Content-Security-Policy" content="default-src 'unsafe-inline' data: gap: *;child-src data: gap: * 'self' data: gap: *;media-src data: gap: *;frame-ancestors 'unsafe-inline' data: gap: *;"/>
        <!--<link rel="stylesheet" type="text/css" href="css/index.css" />-->
        <link rel="stylesheet" type="text/css" href="js/jquery/jquery.mobile-1.4.5.min.css">
        <title>Storage</title>
    </head>
    <body>
        <input type="url" id="file_url" value="" />
        <input type="button" id="download_btn" value="Download"/>
        <input id="video" type="button" name="video" value="video">
        <input id="audio" type="button" name="audio" value="Audio">
        <input id="PDF" type="button" name="pdf" value="PDF">
        <input id="comprobacion" type="button" name="comprobacion" value="Comprobacion">
        <div id="message"></div>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/jquery/jquery-2.1.4.min.js"></script>
        <script type="text/javascript" src="js/jquery/jquery.mobile-1.4.5.min.js"></script>
        <script type="text/javascript" src="js/comportamiento.js"></script>
        <script type="text/javascript" src="js/eventos.js"></script>
        <!--<script type="text/javascript" src="js/index.js"></script>-->
        <!--<script type="text/javascript">
            app.initialize();
        </script>-->
    </body>
</html>

The following is the comportamiento.js (the file than execute the code):

//The directory to store data
var store;

//Used for status updates
var $status;

//URL of our asset
var assetURL;

//File name of our important data file we didn't ship with the app
var fileName;

function init() {
    assetURL=encodeURI(document.getElementById('file_url').value);
    fileName=assetURL.split('/');
    $status = document.querySelector("#message");
    $status.innerHTML = "Checking for data file.";
    store = cordova.file.dataDirectory;
    //Check for the file. 
    window.resolveLocalFileSystemURL(store + fileName[fileName.length-1], appStart, downloadAsset);

}

function downloadAsset() {
    var fileTransfer = new FileTransfer();
    console.log("About to start transfer");
    fileTransfer.download(assetURL, store + fileName, 
        function(entry) {
            console.log("Success!");
            appStart();
        }, 
        function(err) {
            console.log("Error");
            console.dir(err);
        });
}

//I'm only called when the file exists or has been downloaded.
function appStart() {
    console.log(cordova.file.dataDirectory+"/"+fileName[fileName.length-1]);
    $status.innerHTML = "Descarga completa en la url: "+store + fileName[fileName.length-1];
}

function comprobacion(){
    assetURL=encodeURI(document.getElementById('file_url').value);
    fileName=assetURL.split('/');
    $status = document.querySelector("#message");
    $status.innerHTML = "Checking for data on the divece.";
    store = cordova.file.dataDirectory;
    window.resolveLocalFileSystemURL(store + fileName[fileName.length-1], comprobacionSucces, comprobacionError);
}

function comprobacionSucces(){
    $status.innerHTML = "Se encontro archivo en la siguiente ruta "+cordova.file.dataDirectory+fileName[fileName.length-1]; 
}

function comprobacionError(){
    $status.innerHTML = "No!! se encontro archivo en la siguiente ruta "+cordova.file.dataDirectory+fileName[fileName.length-1];    
}

Events triggered with JQuery Mobile Version 1.4.5 and JQuery Version 2.1:

$(document).on("vclick", "#download_btn",function() {
        console.log("si se ejecuta el boton de descarga");
        document.addEventListener("deviceready", init, false);
    });

    $(document).on("vclick", "#video",function() {
        console.log("si se ejecuta el boton video");
        //$(":mobile-pagecontainer").pagecontainer("change", "video.html",{reload:"true"});
        window.location="video.html";
    });

    $(document).on("vclick", "#audio",function() {
        console.log("si se ejecuta el boton audio");
        //$(":mobile-pagecontainer").pagecontainer("change", "video.html",{reload:"true"});
        window.location="audio.html";
    });

    $(document).on("vclick", "#PDF",function() {
        console.log("si se ejecuta el boton PDF");
        //$(":mobile-pagecontainer").pagecontainer("change", "video.html",{reload:"true"});
        window.location="js/pdf.js/web/viewer.html";
    });

    $(document).on("vclick", "#comprobacion",function() {
        console.log("Comprobando...");
        comprobacion();
    });

this is the entired proyect:
https://mega.nz/#!KwgnBZbT!Iz_DTlPxNMWq0vfdPKqf2k6x4OR2trSw6GJJJNhBcGA

Possible SOLUTION:
this is a post than found a momentary solution of this problem:
http://community.phonegap.com/nitobi/topics/phonegap-cli-5-2-0-file-transfer-is-not-working
They recomend than make a downgrade from 5.2.0 to Phonegap 5.1.1 i will tried and replay my experience here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions