I want to create a function for file download from my server but is not working

I want to create a function for file download from my ser but is not working
below my code .

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

Please help me anyone
Thanks

@flycoders_sourav

could you print here your error?

thanks

I’m confused. You download an .mp4 file and save it as an .pdf?

its also not working

download(){

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

Below my plugin list
plugin

download(){

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

But this does nothing, neither throws any error. Any help?

Hi, @flycoders_sourav

try below code:

download(){

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.dataDirectory + 'SampleVideo_1280x720_1mb.mp4',true).then((entry) => {
    console.log('download complete: ' + entry.toURL());
  }, (error) => {
    // handle error
  });
	}

otherwize create folder:
install ionic native File plugin

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.dataDirectory +'video/'+ 'SampleVideo_1280x720_1mb.mp4',true).then((entry) => {
    console.log('download complete: ' + entry.toURL());
  }, (error) => {
    // handle error
  });

Hope this will resolve your issue

thanks

@addwebsolution how to set target path please give me an example

I’m set the tagetpath look like this. am i right?
let targetPath = this.file.documentsDirectory;

yes, you are right @flycoders_sourav

@addwebsolution but it is not working

@flycoders_sourav

what is the error ? could you print here please.

thanks

The console is not showing anything