Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 229693

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

$
0
0

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


Viewing all articles
Browse latest Browse all 229693

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>