glasswing
glasswing

Reputation: 41

file url to a file sitting in the Documents folder in a phonegap iOS app?

what does a file url to a file under the documents folder on my phonegap iOS app look like if i need to reference it in my html file?

Upvotes: 4

Views: 3627

Answers (3)

meadlai
meadlai

Reputation: 935

getAbsolutePath("mead.jpg",
                        function(entry){
                            //alert(entry.fullPath);
                            $("#img_test").attr("src",entry.fullPath);
                            console.log("jq$:=" + entry.fullPath);
                            //$("#img_test").attr("src","img/test.jpg");
                        });

// file system
    function getAbsolutePath(file_name,call_back){
        var full_path = "";
        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, 
               function (file_system){
                    file_system.root.getFile(
                        file_name, 
                        {create: false},
                        call_back
                        , 
                        function(){
                            console.log("failed to fetch file, please check the name");
                        }
                    );

                }, 
                function(){
                    console.log("failed file sytem");
                }
        );


    }

Upvotes: 2

Basil
Basil

Reputation: 889

I reference images saved in the documents folder like this: /var/mobile/Applications/21F126D3-D345-490D-91C6-7619CC682944/Documents/'name'.jpg

The part with the letters and numbers is individual for each app, so yours will be different. You can get this with:

 window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSys) {
    var pathToRoot = fileSys.root.fullPath;
}, function() {
    console.log('****iPhone:Error when requesting persisten filesystem to find root path.');
});

This is explained in the phonegap docs.

Upvotes: 0

at0mzk
at0mzk

Reputation: 1942

the www folder in your phonegap project is the root. so for example a image.png in that folder is added with

<img src="image.png" />

Upvotes: 0

Related Questions