title: Phonegap build - download remote file to documents directory on iOS
body: <p>I'm trying to download an external file to my iOS app built with phonegap build (phonegap 3.3). The file is created and downloaded, but this size is only 4Kb, and it is corrupted. I tried with another file in another server, and I get the same result.</p>
  
  <p>This is my code (based on the file download example on github):</p>
  
  <pre><code>    &lt;div class="app"&gt;
          &lt;h1&gt;PhoneGap&lt;/h1&gt;
          &lt;div id="deviceready" class="blink"&gt;
  
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;script type="text/javascript" src="phonegap.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
          document.addEventListener('deviceready', onDeviceReady, false);
  
          function downloadFile() {
              console.log('downloadFile');
              window.requestFileSystem(
                  LocalFileSystem.PERSISTENT,
                  0,
                  onRequestFileSystemSuccess,
                  fail
              );
          }
  
          function onRequestFileSystemSuccess(fileSystem) {
              console.log('onRequestFileSystemSuccess');
              fileSystem.root.getFile(
                  'dummy.html',
                  {create: true, exclusive: false},
                  onGetFileSuccess,
                  fail
              );
          }
  
          function onGetFileSuccess(fileEntry) {
              console.log('onGetFileSuccess!');
              var path = fileEntry.toURL().replace('dummy.html', '');
              var fileTransfer = new FileTransfer();
              fileEntry.remove();
  
              fileTransfer.download(
                  'http://www.w3.org/2011/web-apps-ws/papers/Nitobi.pdf',
                  path + 'theFile3.pdf',
                  function(file) {
                      console.log('download complete: ' + file.toURI());
                      showLink(file.toURI());
                  },
                  function(error) {
                      console.log('download error source ' + error.source);
                      console.log('download error target ' + error.target);
                      console.log('upload error code: ' + error.code);
                  }
              );
          }
  
          function showLink(url) {
              alert(url);
              var divEl = document.getElementById('deviceready');
              var aElem = document.createElement('a');
              aElem.setAttribute('target', '_blank');
              aElem.setAttribute('href', url);
              aElem.appendChild(document.createTextNode('Ready! Click To Open.'))
              divEl.appendChild(aElem);
          }
  
          function fail(evt) {
              console.log(evt.target.error.code);
          }
  
          /* When this function is called, PhoneGap has been initialized and is ready to roll */
          function onDeviceReady() {
              console.log('device ready!');
              downloadFile();
          }
      &lt;/script&gt;
  </code></pre>
  
  <p>So I get the url in the alert at showLink function, but the file doesn't load. Looking at it with ipad file explorer, I see the file in the documents folder, but it is corrupted and only 4kb!</p>
  
  <p>This is my config.xml file (maybe I'm missing some plugin or permission??):</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;widget xmlns = "http://www.w3.org/ns/widgets"
      xmlns:gap = "http://phonegap.com/ns/1.0"
      id        = "com.phonegap.example"
      version   = "1.0.0"&gt;
  
  &lt;name&gt;download&lt;/name&gt;
  
  &lt;description&gt;
  download example
  &lt;/description&gt;
  
  &lt;gap:plugin name="org.apache.cordova.dialogs" /&gt;
  &lt;gap:plugin name="org.apache.cordova.file" version="1.0.1" /&gt;
  &lt;gap:plugin name="org.apache.cordova.file-transfer" version="0.4.2" /&gt;
  
  &lt;feature name="File"&gt;
      &lt;param name="ios-package" value="CDVFile" /&gt;
  &lt;/feature&gt;
  &lt;feature name="FileTransfer"&gt;
      &lt;param name="ios-package" value="CDVFileTransfer" /&gt;
  &lt;/feature&gt;
  
  &lt;author href="https://example.com" email="you@example.com"&gt;
  Your Name
  &lt;/author&gt;
  
  &lt;/widget&gt;
  </code></pre>
  
  <p>What is wrong here? If someone have another example for download an external file to <strong>iOS</strong> it will be fine too.</p>