saman0suke
saman0suke

Reputation: 762

Phonegap Download file in iOS with File-Transfer and access to it in the device

I created an application using Phonegap and jQuery Mobile, it works great in an iPad mini, and I'm using File-Transfer to download a file in the device, the log says the file was successfully downloaded but I can't find the pdf document anywhere in the device, this is my code:

function iosDownload() { 
    var fileTransfer = new FileTransfer(); 
    var uri = encodeURI("WEB_SERVICE_URL"); 

    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fs) { 
        var fileNamePath = fs.root.fullPath + "/file.pdf"; 
        fileTransfer.download( uri, fileNamePath, function(entry) { 
            console.log("download complete: " + entry.fullPath); 
            alert("Reporte generado exitosamente"); 
            }, function(error) { 
                console.log("download error source " + error.source); 
                console.log("download error target " + error.target); 
                console.log("upload error code" + error.code); 
                alert("Error al generar reporte. Intentar mas tarde"); 
            }, false, { 
                headers: { 
                    "Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA==" 
                } 
            } 
        ); 
    }); 
} 

The response in the log shows this path:

download complete: /var/mobile/Containers/Data/Application/DEVICE_UNIQUEID/Documents/file.pdf

I cannot find the document, is there any way to download it in the Downloads folder? or is there any way to find it in that location? thanks.

Upvotes: 0

Views: 1970

Answers (1)

Phyo
Phyo

Reputation: 692

Look into this file path

Users/YourAccount/Library/Developer/CoreSimulator/Devices/45BCFA0B-C37A-4A85-A63C-(device's ID)/data/Containers/Data/Application/E4472D7E-A833-4985-89CF-(App's ID)/Documents/yourfile.pdf

Hope that help. Same path you saved.

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fs) { 
    var fileNamePath = fs.root.fullPath + "/file.pdf"; 
    $scope.fileToShow = fileNamePath;

}

HTML

<div>fileToShow</div>

If you want to see your pdf on your iPad, install iExplorer

iExplorer

Connect your iPad and open iExplorer. Then go to Files and Apps,and select your application. Your pdf will be under Documents.

Upvotes: 1

Related Questions