File dwonload issue from extarnal url


#1

I’m try to download file form the external url below my code but its dose not working
Please helpme anyone.

download(){

  let targetPath = this.file.documentsDirectory;
  alert("hello")
    this.file.createDir(targetPath,'video',true)
 .then((res) => console.log('createDir video res',res))
 .catch((err) => console.log('createDir video err',err));

const fileTransfer: FileTransferObject = this.transfer.create();
 const url =   "http://codersthought.com/sourav/videostatus/wp-content/uploads/2014/12/SampleVideo_1280x720_1mb.mp4";
var URL = encodeURI(url);
  fileTransfer.download(URL, this.file.externalRootDirectory  +'video/'+ 'SampleVideo_1280x720_1mb.mp4',true).then((entry) => {
    console.log('download complete: ' + entry.toURL());
  }, (error) => {
    // handle error
  });
}

#2

Hi, @flycoders_sourav you are getting any error?


#3

no am not getting any error


#4

if you are using android platform use externalDataDirectory,

this.file.externalDataDirectory;

if you are using ios platform use documentsDirectory,

this.file.documentsDirectory;


#5

its also not working bellow my code


  let targetPath = this.file.documentsDirectory;
  alert("hello")
    this.file.createDir(targetPath,'video',true)
 .then((res) => console.log('createDir video res',res))
 .catch((err) => console.log('createDir video err',err));

const fileTransfer: FileTransferObject = this.transfer.create();
 const url =   "http://demo.com/sourav/videostatus/wp-content/uploads/2014/12d/SampleVideo_1280x720_1mb.mp4";
var URL = encodeURI(url);
  fileTransfer.download(URL, this.file.externalDataDirectory +'video/'+ 'SampleVideo_1280x720_1mb.mp4',true).then((entry) => {
    console.log('download complete: ' + entry.toURL());
  }, (error) => {
    // handle error
  });
}

#6

ok what response you are getting in console.log('download complete: ' + entry.toURL());


#7

pls, print error like this,

}, (error) => {
   console.log('err',error);
  });

#8

nothing happening in the console. also i give the value ot entry.toURL inside the alert


#9

showing this error createDir video err cordova_not_available


#10

ok, build your app in android or ios device and check.

I think your code is right but you need to check in real device and check your downloaded file in this path 'file:///storage/emulated/0/Android/data/your_app_name/files/video/SampleVideo_1280x720_1mb.mp4'


#11

can i c change the path?


#12

Which path do you want to change?


#13

i cant find my app name folder inside the storage


#14

Got it.but i want o change the download Katha locations and i want to download progress bar how can do that?


#15

hi, @flycoders_sourav

try below plugin for download progress bar

https://github.com/katzer/cordova-plugin-local-notifications

thanks


#16

for what @addwebsolution ?


#17

i want to change the download downloaded path how can i change that?


#18

download path i want to change and i want to create a folder of my app name