How to check file downloaded or not .I want to check If the file is already downloaded then only will be shared and if the file does not exist then it will be shared with the download how can i do that please help me anyone
Below my code
public downloadfacebookSahre(event,item){
let getUrl = this.selectedItem._meta_video_status
let downloadFileName = getUrl.substr(getUrl.lastIndexOf('/') + 1);
this.file.checkFile(this.storageDirectory, downloadFileName)
.then(() => {
let finaleLink = this.storageDirectory+downloadFileName;
let getFileNamephone = getUrl.substr(getUrl.lastIndexOf('/') + 1);
if(getFileNamephone == downloadFileName){
this.facebookShare(event,item);
}else{
this.presentToast('Download started..');
this.platform.ready().then(() => {
const fileTransfer: FileTransferObject = this.transfer.create();
let getUrl = this.selectedItem._meta_video_status
let downloadFileName = getUrl.substr(getUrl.lastIndexOf('/') + 1);
//const imageLocation = `${cordova.file.applicationDirectory}www/assets/img/${item}`;
const url = getUrl;
var URL = encodeURI(url);
this.loading = this.loadingCtrl.create({
content: 'Downloading...',
});
this.loading.present();
fileTransfer.download(url, this.storageDirectory + downloadFileName).then((entry) => {
this.loading.dismissAll()
this.presentToast('Download complete !');
//this.facebookShare(event,item);
}, (error) => {
this.presentToast('Download faild, try again !');
});
});
}
})
.catch((err) => {
});
}
public facebookShare(event,item){
let getUrl = this.selectedItem._meta_video_status
let downloadFileName = getUrl.substr(getUrl.lastIndexOf('/') + 1);
this.file.checkFile(this.storageDirectory, downloadFileName).then(() => {
let finaleLink = this.storageDirectory+downloadFileName;
this.socialSharing.shareViaFacebook(
`Share via ${this.appUrl}`,
finaleLink
).then(() =>{//this.presentToast('Your video has been successfully shared on facebook!');
},
()=>{
this.presentToast('Download faild, try again !');
})
})
.catch((err) => {
});
}
Please guide me.
Thanks