I am creating one application where I am downloading .mp3 audios from remote server using file transfer native plugin on ionic. In android it is working fine. But in iOS (11.3) its not working properly. It is downloading the file but the file with 2bytes is only downloading.
downloadAudio(url){
if (this.network.type == 'none') {
this.loadingProvider.presentToast('Please Connect Internet.');
}else{
var URL = encodeURI(url);
var fileName = URL.substring(URL.lastIndexOf("/") + 1, URL.length);
if(this.platform.is('ios')) {
this.appTargetPath = this.file.documentsDirectory;
}else{
this.appTargetPath = this.file.externalDataDirectory;
}
this.targetPath = this.appTargetPath+'audios/';
this.file.checkFile(this.targetPath, fileName).then((fileStatus) => {
// check audio file exits or not
if (fileStatus == true) {
this.loadingProvider.presentToast('Audio already present.');
}
}).catch(err => {
this.file.listDir(this.appTargetPath,'audios')
.then(res => {
var audioLength = res;
// Download audio file
this.loadingProvider.presentToast('Audio is downloading...');
const fileTransfer: FileTransferObject = this.transfer.create();
var options = {};
console.log('URL',URL);
console.log('targetPath',this.targetPath);
console.log('fileName',fileName);
fileTransfer.download(URL,this.targetPath+fileName).then((entry) => {
console.log('entry',entry);
this.loadingProvider.presentToast('Audio download successfully.');
}, (error) => {
this.loadingProvider.presentToast('Error while downloading audio.');
});
}).catch(err => {
console.log('err',err);
this.loadingProvider.presentToast('Error while fetching audio.');
});
});
}
}
Any help would be appreciable.