Cordova 3.3 - fileSystem.root.fullPath returns “/” instead of full path

…衆ロ難τιáo~ 提交于 2019-12-22 05:34:16

问题


I had a piece of code working with Cordova 2.7. I upgraded my app to Cordova 3.3 along with upgrading all the custom plugins I developed.

I was successfully able to get the full absolute path of the Documents directory on iOS with Cordova 2.7, but with Cordova 3.3 it just returns / for the fullPath

Here is my code:

window.requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem;
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);

function gotFS(fileSystem) {
    alert("entered gotFS: " + fileSystem.root.fullPath);
}

I tested this on iPad Simulator 7.0 (which was giving correct results with Cordova 2.7)

Although, I can get the path with other methods, I would prefer to use the Cordova API.

The API documentation doesn't mention anything about this. Any idea what could be wrong?


回答1:


try changing fullpath to toURL() and test

window.requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem;
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);

function gotFS(fileSystem) {
  alert("entered gotFS: " + fileSystem.root.toURL());
}



回答2:


Since few users requested for my answer, here is how I managed to get the Documents directory path:

var documentsDirectoryPath = decodeURIComponent(window.location.href);
documentsDirectoryPath = documentsDirectoryPath.substring("file://".length);
documentsDirectoryPath = documentsDirectoryPath.substring(0, documentsDirectoryPath.indexOf("/<<YOUR_APP_NAME>>.app/www/index.html"));
documentsDirectoryPath += "/Documents";

Remember to replace YOUR_APP_NAME with your app's name



来源:https://stackoverflow.com/questions/22036956/cordova-3-3-filesystem-root-fullpath-returns-instead-of-full-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!