【问题标题】:Cordova file plugin not working to delete a fileCordova 文件插件无法删除文件
【发布时间】:2019-05-09 08:34:04
【问题描述】:

我一直在使用 AngularJS、Cordova 和 Ionic 开发应用程序。过去,我一直在使用 Cordova 文件插件将一些信息存储在设备上的文件中。

我想放弃这种方法并删除文件。

这是我的代码 sn-p:

function migrateAwayFromDataFile() {

    console.log(' migrate away from data file ');

    console.log(cordova.file.dataDirectory); //file:///data/data/com.myapp.app/files/

    window.requestFileSystem(cordova.file.dataDirectory, 0, function (fs) {
        fs.root.getFile('filename.json', { create: false }, function (fileEntry) {
            fileEntry.remove(function () {
                console.log(' config file deleted ');
                ErrorMessageAndDebugLogService.logDebug('Config file has been deleted successfully.');
            }, function (error) {
                console.log(error);
                ErrorMessageAndDebugLogService.logDebugError('Could not delete Config file. ' + JSON.stringify(error));
            });
        });
    });
}

我不断收到这些错误:

 migrate away from data file 
bundle.min.js:1 file:///data/data/com.myapp.app/files/
cordova.js:420 Wrong type for parameter "type" of requestFileSystem: Expected Number, but got String.
checkArgs @ cordova.js:420
cordova.js:422 Uncaught TypeError: Wrong type for parameter "type" of requestFileSystem: Expected Number, but got String.
    at Object.checkArgs (cordova.js:422)
    at requestFileSystem (plugins/cordova-plugin-file/www/requestFileSystem.js:50)
    at bundle.min.js:1
    at Object.l [as initializeApp] (bundle.min.js:1)
    at bundle.min.js:1
    at Array.<anonymous> (vendors.min.js:1)
    at Channel.o (vendors.min.js:1)
    at Channel.fire (cordova.js:840)
    at cordova.js:226

为什么它不起作用?

【问题讨论】:

    标签: javascript android file cordova cordova-plugins


    【解决方案1】:

    requestFileSystem() 的第一个参数必须是类型,而不是目录:

    window.requestFileSystem('json' 
    

    【讨论】:

      猜你喜欢
      • 2017-03-12
      • 2016-07-02
      • 2023-03-06
      • 1970-01-01
      • 2012-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-17
      相关资源
      最近更新 更多