我正在编写一个小应用程序,用于从连接对象(空气净化器......)下载统计信息。
我想将文件从网络服务器下载到手机(目前为Android)。
这样做,我得到一个NOT_FOUND_ERR;但该文件确实存在于Web服务器上,并且在我的手机上不存在新文件。
(这可能会有所帮助:当我创建一个目录时,它不会落入Android / com.air_serenity.appli / files或/ cache目录。我只是不知道它在哪里创建。但它确实如此。存在,因为我不能通过重新启动应用程序来创建它两次。我决定坚持这个非阻塞错误,但它可能与我当前的问题有关。)
我使用最新的Cordova版本,以及相关的插件(File和FileTransfer)。
以下是代码:
function onDeviceReady() {
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
if (localStore) window.webkitStorageInfo.requestQuota(PERSISTENT, 1024*1024*10, function(grantedBytes) {
window.requestFileSystem(PERSISTENT, grantedBytes, onFileSystemSuccess, fail);
}, fail);
}
function onFileSystemSuccess(fileSystem) {
// creating a directory does work.
// I can also create a file in the directory. I cannot see where the file is created, but I cannot create it twice, which means that it is somewhere...
fileSystem.root.getDirectory('3JLGRJD', {create: true, exclusive: false}, function(dirEntry2){
var fileTransfer = new FileTransfer();
var uri = encodeURI('http://www.air-serenity.science/cache/3/J/L/G/R/J/D.air');
fileTransfer.download(uri, dirEntry2.fullPath + 'D.air',
function(entry) {alert("ok");},
fail,
{}
);
}, fail );
}
function fail(evt) {alert('Error: ' + evt.code);}
任何人都可以帮我找到遗失的东西吗? 非常感谢!