【问题标题】:Copying a file into internal storage in Cordova将文件复制到 Cordova 的内部存储中
【发布时间】:2018-01-05 10:31:02
【问题描述】:

我有一个 Cordova 移动应用程序,并且我正在实现一个导入功能。用户应将文件clients.db 放在Documents 文件夹中,从应用程序启动导入功能,应用程序本身应将此文件从当前位置复制到内部数据库存储,准备作为SQLite 打开数据库

这是我的代码:

window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory + "/Documents/clients.db", function(fs) {
    window.resolveLocalFileSystemURL("file://data/data/com.app.clients/databases/",function(directoryEntry) {
       fs.copyTo(directoryEntry, "clients.db", function() {
          //done
       }, function(err) {
          //here I get err = 1
       });
    }, function(){
        //err
    });
}, function(){
    //err
});

文件clients.db 位于Documents 文件夹中,但是当我启动代码时,copyTo 函数无法返回 err = 1,这意味着找不到文件。

在调试时,我注意到变量 fs 的值正确:

filesystem : FileSystem fullPath : "/Documents/clients.db" isDirectory : false isFile : true name : "clients.db" nativeURL : "file:///storage/emulated/0/Documents/clients.db"
__proto__ : Entry

directoryEntry 也是正确的,它被识别为一个目录

【问题讨论】:

    标签: android sqlite cordova cordova-plugins


    【解决方案1】:

    url 是否与文件夹路径匹配?看起来很奇怪。

    【讨论】:

    • 你的意思是 file:///data/data/com.app.clients/databases/ ??为什么看起来很奇怪?
    • 一个是解析origin,一个是解析destination。我做错了吗?
    • sry 没看到你使用 fs。看看你可以读取文件并向目标文件夹写入内容
    • 使用任何cordova函数的根路径是什么意思?
    【解决方案2】:

    参考我的代码here。 from 位置应该在第一个 resolveLocalFileSystemURL 调用和第二个的 to 位置。

    【讨论】:

      猜你喜欢
      • 2023-03-05
      • 2015-09-14
      • 2012-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-26
      相关资源
      最近更新 更多