PhoneGap resolveLocalFileSystemURI [英] PhoneGap resolveLocalFileSystemURI

查看:233
本文介绍了PhoneGap resolveLocalFileSystemURI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试解析此文件系统uri,如下所示:

I am trying to resolve this filesystem uri shown below:

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

任何机构都可以告诉我如何在PhoneGap中解决这个uri,并使用下面显示的方法获取FileEntry?

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);

我试图在uri之前添加file://或//不工作。

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

感谢。

推荐答案

PhoneGap不会允许您读取[APP HASH] / Documents或[APP HASH] / tmp文件夹之外的文件。除非你能找到一个方法来初始化你的应用程序与您的数据在其中一个文件夹,你将不得不以另一种方式获取您的数据。我发现下面的代码工作。基本上,它会将本地文件下载到您的临时文件夹,并为您提供文件条目。

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);

这篇关于PhoneGap resolveLocalFileSystemURI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆