我正在使用一个应用程序在其中创建脱机PDF并将其保存在文件系统中。 现在的问题是,当我删除特定记录时,我需要通过文件插件从文件系统中删除PDF,但是找不到与此相关的任何方法。我正在使用Ionic 4,这是一些安全的代码。
if (this.plt.is('cordova')) {
this.pdfObj.getBuffer((buffer) => {
const blob = new Blob([buffer], { type: 'application/pdf' });
// Save the PDF to the data Directory of our App
this.file.writeFile(this.file.externalRootDirectory + '/Downloads/', 'ACCSYS-' +
this.randomString(4) + '-' + encodeURI(this.headerData.title) + '.pdf', blob, { replace: true }).then(fileEntry => {
// Open the PDf with the correct OS tools
setTimeout(() => {
this.hideLoader();
this.fileOpener.open(fileEntry.nativeURL, 'application/pdf');
this.pdfObj = null;
}, 1000);
});
});
} else {
setTimeout(() => {
this.hideLoader();
this.pdfObj.download();
this.pdfObj = null;
}, 500);
}
假设我将nativeURL存储在本地存储中。
任何想法如何删除文件??
答案 0 :(得分:1)
答案 1 :(得分:0)
这是执行此操作的最佳方法(在ts文件顶部定义窗口)
delete() {
// this.fileHelper.removeFile();
const fileToRemove = this.remoteURL; // Change this with your file path
window.resolveLocalFileSystemURL( fileToRemove, (dirEntry) => {
dirEntry.remove(this.successHandler, this.errorHandler);
});
}
successHandler() {
console.log('Directory deleted successfully');
}
errorHandler() {
console.log('There is some error while deleting directory')
}