简体   繁体   中英

PhoneGap file download not working properly on IOS devices

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.

Finally I got my solution.

 <access origin="*" /> 

Above my code is working fine for download from URL in both android and IOS. Creating folder and download in it.

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