Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
698 views
in Technique[技术] by (71.8m points)

file - PhoneGap resolveLocalFileSystemURI

I am trying to resolve this filesystem uri shown below:

/var/mobile/Applications/9483756B-8D2A-42C5-8CF7-8D76AAA8FF2C/Shift.app/iqedata/5977e2e9239649d5a7e3b8a54719679f/06e2b8896e51472789fcc27575631f94.jpg

Can any body tell me how to resolve this uri in PhoneGap and get the FileEntry by using the method showing below?

window.resolveLocalFileSystemURI(Url, resOnSuccess, resOnError);

I have tried to add "file://" or "//" before the uri but it doesn't work.

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

PhoneGap will not let you read files outside of the [APP HASH]/Documents or [APP HASH]/tmp folders. Unless you can find a way to initialize your app with your data in one of these folders, you will have to get your data another way. I have found the below code to work. Basically it downloads the local file into your temp folder and gives you the file entry.

window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, function(fs){
    fs.root.getFile("temp", {create: true, exclusive: false},
      function(entry){
        fileTransfer.download(
                Url, // the filesystem uri you mentioned
                entry.fullPath,
                function(entry) {
                    // do what you want with the entry here
                    console.log("download complete: " + entry.fullPath);
                },
                function(error) {
                    console.log("error source " + error.source);
                    console.log("error target " + error.target);
                    console.log("error code " + error.code);
                },
                false,
                null
        );
    }, function(){
        alert("file create error");
    });
}, null);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...