I am using PhoneGap version 2.9.0 to download file from URL to specific folder. Which is working fine for me in android, as file get download in specific folder, but in case of IOS devices file is not download fully.
Ex. IF file size = 2.3mb and download file size = 111 bytes
My code -
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, fileSystemSuccess, fileSystemFail);
function fileSystemSuccess(fileSystem) {
var uri = $("#URL").val(); // Get URL
var download_link = encodeURI(uri);
var path = download_link,
ext = path.substr(path.lastIndexOf('.') + 1); //Get extension of URL
var folder_name = $("#folder").val(); // Get folder name
var file_name = $("#filename").val(); //Get file name
var directoryEntry = fileSystem.root; // to get root path to directory
directoryEntry.getDirectory(folder_name, { create: true, exclusive: false }, onDirectorySuccess, onDirectoryFail); // creating folder in sdcard
var rootdir = fileSystem.root;
var fp = rootdir.fullPath;
fp = fp + "/" + folder_name + "/" + file_name + "." + ext; // fullpath and name of the file which we want to give
// download function call
var fileTransfer = new FileTransfer();
//File download function with URL and local path
fileTransfer.download(download_link, fp,
function (entry) {
alert("download complete: " + entry.fullPath);
},
function (error) {
alert("download error source " + error.source);
alert("download error target " + error.target);
alert("upload error code" + error.code);
}
);
}
function onDirectorySuccess(parent) {
//alert(parent);
}
function onDirectoryFail(error) {
//Error while creating directory
alert("Unable to create new directory: " + error.code);
}
function fileSystemFail(evt) {
alert(evt.target.error.code);
}
Folder is creating in IOS, issue is only download file size. I am stuck with this IOS issue. Help me out.