0

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.

Suhas Gosavi
  • 2,170
  • 19
  • 40

1 Answers1

0

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.

Suhas Gosavi
  • 2,170
  • 19
  • 40
  • How did you see the file in iOS devices? – Lavanya Jun 20 '14 at 07:56
  • http://stackoverflow.com/questions/21577230/phonegap-save-image-from-url-into-device-photo-gallery/21579097#21579097 this is probably gd solution to download a file – Suhas Gosavi Jun 20 '14 at 08:55
  • @AdisAksh you can find it in file manager or there are resources available to check file systems of your apple devices. – Suhas Gosavi Jun 20 '14 at 08:56
  • When I download the file from server, I can able to see xCode but not able to see in device. I have installed more application in device that time also not able to see. Could u pls tell me the app name? – Lavanya Jun 20 '14 at 09:40
  • @AdisAksh http://lifehacker.com/5914638/the-best-desktop-file-explorer-for-iphone refer this or google it there are many apps like this to view files from apple devices on windows and Go to your download file path – Suhas Gosavi Jun 20 '14 at 10:52
  • my download file path is var/mobile/Applications/Some ID/documents/file...How should I see this path? I have tried lot of app like FileManager,FileApp,Documets2,FileExplorer and iFunBox.Not able to see my downloaded file within this app. – Lavanya Jun 20 '14 at 11:01
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/55976/discussion-between-suhas-and-adisaksh). – Suhas Gosavi Jun 20 '14 at 11:30