使用Cordova/PhoneGap 3.3.0,我使用FileTransfer插件下载文件,然后尝试使用InAppBrowser插件打开它。 我可以成功下载文件,并将其放置在临时目录中。由于File插件现在使用URL架构,因此我无法弄清楚如何将正确的url /路径传递给InAppBrowser插件的window.open
方法。我也找不到任何相关的文档。我能找到的所有“下载和打开”文档都是过时的,并且是URL-schema。Cordova/PhoneGap打开已下载的文件(InAppBrowser)
相关链接:
- Cordova Release info on New Plugin Versions
- The readme for the FileTransfer plugin
- The readme for the InAppBrowser plugin
- How to open local file with InAppBrowser with recent changes to URL scheme in File plugin - 类似的问题
已过期前的amples我发现:
- File-transfer download file issue on Cordova 3.1 - 这个用户降级到较早的版本,因为他们无法弄清楚
- https://gist.github.com/devgeeks/4982983 - 这个例子使用
entry.fullPath
,现在废弃了的toURL()
这里是我的代码:
var uri = encodeURI("http://some.url/file.pdf");
window.requestFileSystem(LocalFileSystem.TEMPORARY, 0,
function (fileSystem) {
var fileTransfer = new FileTransfer();
var filename = fileSystem.root.toURL() + uri.substr(uri.lastIndexOf("/") + 1);
fileTransfer.download(uri, filename,
function(entry) { // download success
var path = entry.toURL(); //**THIS IS WHAT I NEED**
window.open(path, "_system");
},
function(error) {} // irrelevant download error
);
},
function(error) {} // irrelevant request fileSystem error
);
我目前TE在Nexus 7和Nexus 5上使用Android。InAppBrowser正确打开默认的PDF启动器(在我的情况下是Adobe Reader),但是后来出现“文档路径无效”错误。
[更新:显示返回值]
我已经尝试了所有的文件路径如下组合:
var path = entry.toURL(); // "cdvfile://localhost/temporary/file.pdf"
var path = entry.fullPath; // "file.pdf"
var path = fileSystem.root.toURL() + filename; // "cdvfile://localhost/temporary/file.pdf"
var path = fileSystem.root.fullPath + filename; // "/file.pdf"
如果您最近更新了插件,也许您必须处理新的URL方案'cdvfile://'? http://cordova.apache.org/news/2014/02/10/plugins-release.html – QuickFix
感谢您的评论。我正在使用这些最新的插件,在您提供的链接中引用。我读了这个,但不记得我发布的URL。我将它添加到相关链接部分。当我调用'entry.toURL()'我得到'cdvfile://'前缀的链接 – chadiusvt
愚蠢的问题:为什么不直接使用window.open而不是先下载它的原始URL? – QuickFix