How to check file downloaded or not


#1

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


#2

After download you will get entry. entry.toURL() gives you the path where file is stored.


#3

Can you make the changes in my codeā€¦because I am not much more knowledge on ionic 2


#4

check this out to understand the concept of cordova file transfer.

https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file-transfer/