title: Ionic 2 - How to setup file download?
body: <p><strong>THE SITUATION:</strong></p>
  
  <p>In my Ionic 2 app I have a <em>Documents</em> section where the user should be able to download files.</p>
  
  <p>I am trying to setup the <a href="https://ionicframework.com/docs/v2/native/transfer/" rel="nofollow noreferrer">file transfer</a> for Ionic 2.</p>
  
  <p><strong>THE CODE:</strong></p>
  
  <p><strong>The documents component:</strong></p>
  
  <pre><code>import { Component } from '@angular/core';
  import { NavController } from 'ionic-angular';
  
  import { Transfer } from 'ionic-native';
  
  declare var cordova: any;
  
  @Component({
    selector: 'page-documents',
    templateUrl: 'documents.html'
  })
  
  export class DocumentsPage {
  
      constructor(public navCtrl: NavController) {}
  
      ionViewDidLoad() {
  
      }
  
      downloadFile()
      {
          const fileTransfer = new Transfer();
          let url = 'http://MY_URL.com/example.txt';
  
          fileTransfer.download(url, cordova.file.dataDirectory + 'example.txt').then((entry) =&gt; 
          {
              console.log('download complete: ' + entry.toURL());
          }, (error) =&gt; {
              // handle error
          });
      }
  }
  </code></pre>
  
  <p><strong>THE RESULTS:</strong></p>
  
  <p><strong>In the browser:</strong></p>
  
  <p>I get the following error message: <code>FileTransfer is not defined</code> but probably because cordova doesn't work in the browser.</p>
  
  <p><a href="https://i.stack.imgur.com/NlZT0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NlZT0.png" alt="FileTransfer is not defined"></a></p>
  
  <p><strong>In the emulator:</strong></p>
  
  <p>In the emulator the download seems actually successfull. In the console I can see: <code>donwload complete</code>.  but I didn't see starting any download and there is no trace of the downloaded file.</p>
  
  <p><a href="https://i.stack.imgur.com/3CefF.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3CefF.jpg" alt="donwload complete"></a></p>
  
  <p><strong>In the device:</strong></p>
  
  <p>In the device - after clicking for the download - nothing happens.. I don't see starting any download. In the file manager I don't see the file.</p>
  
  <p><strong>THE QUESTION:</strong></p>
  
  <p>How can I properly setup the file download for Ionic 2?</p>
  
  <p>There is something wrong in the code?</p>
  
  <p>Should I see the download starting in the device?</p>
  
  <p>Thanks!</p>