【发布时间】: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