文件的URL到Phonegap iOS应用程序的Documents文件夹中的文件?
问题描述:
如果我需要在我的html文件中引用文件,那么文件url会在我的phonegap iOS应用程序的文档文件夹下的文件中发挥什么作用?文件的URL到Phonegap iOS应用程序的Documents文件夹中的文件?
答
您的phonegap项目中的www文件夹是根。因此,例如,该文件夹中一个image.png中加入
<img src="image.png" />
答
我参考保存在文档中的图像文件夹是这样的:在/ var /移动/应用/ 21F126D3-D345-490D-91C6-7619CC682944 /文档/ 'name'.jpg
包含字母和数字的部分对于每个应用都是单独的,因此您的将会有所不同。你可以得到这个:
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.');
});
这在phonegap docs解释。
答
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");
}
);
}