【问题标题】:How can i check if file exist with ionic我如何检查文件是否存在离子
【发布时间】:2020-07-22 17:04:57
【问题描述】:

我正在为 android 和 iOS 构建一个移动应用程序我想检查用户 sd 卡或内置内存中是否存在目录,如果该目录不存在,那么我将创建该目录。 我检查了ionic file transfer docs 上的文档,但找不到任何有用的东西,我在网上搜索但找到了一些代码但它不起作用,我要创建的目录的名称是 softik,这是代码

public storageDirectory:any;
download() {
    this.chkmkDir().then(async ()=>{
        const fileTransfer: FileTransferObject = this.fileTransfer.create();
        this.storageDirectory = `${this.file.externalRootDirectory}test.mp4`;
        fileTransfer.onProgress((progressEvent)=>this.progress=Math.round((progressEvent.loaded / progressEvent.total) * 100))
        fileTransfer.download(this.url,this.storageDirectory + 'test.mp4', true).then((entry) => 
            console.log('Berhasil download dan tersimpan di : ' + this.storageDirectory + "test.jpeg"), 
            error => console.log('gagal : ' + JSON.stringify(error)),
        );  
    }).catch(err=>console.log())
}
chkmkDir(){
    return new Promise((resolve, reject)=>{
        this.file.checkDir(this.file.externalRootDirectory, 'softik').then(res=>resolve()
        ).catch(err => {
            this.file.createDir(this.file.externalRootDirectory, 'softik',false).then(res =>resolve())
            .catch(err=>reject(JSON.stringify(err))); 
        });
    })
}

请问我怎么了

【问题讨论】:

    标签: ionic-framework ionic-native


    【解决方案1】:

    首先你应该使用 File 插件 然后你可以搜索文件或目录 请参阅此文档https://ionicframework.com/docs/v3/native/file/#checkFile

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-01
      • 2014-04-16
      • 1970-01-01
      • 1970-01-01
      • 2020-05-28
      • 2011-11-01
      相关资源
      最近更新 更多