简体   繁体   中英

phonegap download and save images from a url to the application installation folder

I am developing an application in phonegap that is supposed to work in both ios and android. For this application i need to download all images from the server.I was able to download the images to the external memory card using the following code.

function storeIntelligrapeLogo() {
alert('start of file download');
var url = "http://www.kannuronlineservices.com/images/logo.png"; // image url
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fs) {
    alert('inside request file sysytem')
    var imagePath = 'file:///storage/sdcard0'+fs.root.fullPath + "/logo.png"; // full file path
    alert('inside request file sysytem path fs.root==' + fs.root);
    alert('inside request file sysytem path fs.root.fullPath==' + fs.root.fullPath);
    var fileTransfer = new FileTransfer();
    fileTransfer.download(url, imagePath, function(entry) {
        alert(entry.fullPath); // entry is fileEntry object
    }, function(error) {
        alert("Some error" + JSON.stringify(error));
    });
}) }

Now i would like this to work in ios also.For that what is the file path i have to use for 'file:///storage/sdcard0'.Then now the file is downloaded to the external memory card in android and i would like it to be downloaded to the application installation folder and so that when the application is uninstalled,the images also get deleted.Or please suggest me if there exist some other way of doing this,ie:downloading images from server folder and storing it locally with phonegap so that the application is expected to work in offline mode also. Thanks.

You can use a phonegap plugin.

Look at http://plugins.cordova.io/#/package/de.fastr.phonegap.plugins.downloader

It downloads multiple files to persistant storage on android and ios.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM