Quantcast
Viewing latest article 6
Browse Latest Browse All 7

Answer by Gokulraj Mahadheeraa for Saving file to Downloads directory using Ionic 3

import { File } from '@ionic-native/file';import { FileTransfer } from '@ionic-native/file-transfer';constructor(private file: File, private transfer: FileTransfer){}let link = 'url_to_download_file';let path = '';let dir_name = 'Download'; // directory to download - you can also create new directorylet file_name = 'file.txt'; //any file name you likeconst fileTransfer: FileTransferObject = this.transfer.create();let result = this.file.createDir(this.file.externalRootDirectory, dir_name, true);result.then((resp) => {  path = resp.toURL();  console.log(path);  fileTransfer.download(link, path + file_name).then((entry) => {    console.log('download complete: '+ entry.toURL());  }, (error) => {    console.log(error)  });}, (err) => {  console.log('error on creating path : '+ err);});

Viewing latest article 6
Browse Latest Browse All 7

Trending Articles