PhonegapBuild simple file download

I built pure html PhoneGap app that works great on Android. It have link to download large video files. Simple direct link. However it does not download on iPhone or iOS. Their browser does not support file download. It tries to play and stutter and then stops.

I need very simple function or code to download file on iOS.

I have no phonegap js or any js, but if needed I can include. Only html and config.xml used. I use PhoneGap Build to create apps from html/css. Thanks!

preguntado el 31 de julio de 12 a las 09:07

1 Respuestas

To download the file (snippet from phonegap doc):

var fileTransfer = new FileTransfer();
var uri = encodeURI("http://some.server.com/download.php");

fileTransfer.download(
    uri,
    filePath,
    function(entry) {
        console.log("download complete: " + entry.fullPath);
    },
    function(error) {
        console.log("download error source " + error.source);
        console.log("download error target " + error.target);
        console.log("upload error code" + error.code);
    }
);

The first param is the url you want to download from, and the last two are the success and error callbacks. The second one is the full path where you want to store the file, including the filename and extension. To get a reference to your app root directory:

function gotFS(fileSystem) {
    console.log("got filesystem");
    // save the file system for later access
    console.log(fileSystem.root.fullPath);
    window.rootFS = fileSystem.root;
}

document.addEventListener('deviceready', function() {
    window.requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem;
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}, false);

So if you are downloading a video called 'video.avi' and would like to store it in the app root folder, the filePath variable you would pass along to the download metod would be something like this:

var filePath = rootFS.fullPath+'/video.avi';

Espero que esto ayude

Respondido 31 Jul 12, 10:07

Thanks on help I included that codes (with mine file to download) and nothing happens, I put alert instead of console.log. Nothing happens. Should I include some phonegap js? Or nothing is needed? - user1539246

what messages are displayed in the console? There should be some of them pointing out what's going on - davids

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.