title: Cannot Save Images from URL in Nativescript/Javascript with imageSource module
body: <h1>Context</h1>
  
  <p>I'm trying to download a users' Facebook profile picture to the local storage so that I can display it without having to remake the call to Facebook.</p>
  
  <h1>Code</h1>
  
  <p>I'm using the module <code>image-source</code> to download the image, and the module <code>file-system</code> to access the device's local storage.</p>
  
  <p>Most of the code is referencing <a href="https://docs.nativescript.org/cookbook/image-source#save-image-source-to-png-or-jpg-file" rel="nofollow noreferrer">the Nativescript <code>image-source</code> documentation page</a>.</p>
  
  <pre><code>var imageSource = require("image-source");
  var fs = require("file-system");
  
  exports.theFunction = function(args){
      //...
          var img = imageSource.fromFile("http://graph.facebook.com/"+user.id+"/picture?type=large");
          var folder = fs.knownFolders.documents();
          var path = fs.path.join(folder.path, "profilePic.jpg");
          console.log(path);
  
          var saved = img.saveToFile(path, enums.ImageFormat.jpg);
          appSettings.setString("imgLocal",path);
  
          console.log("Image Saved Successfully");
      //...
  }
  </code></pre>
  
  <h1>Output</h1>
  
  <blockquote>
    <p>/data/user/0/com.foo.bar/files/profilePic.jpg</p>
  </blockquote>
  
  <p>I never see the "Image Saved Successfully" message output to console and I have no way of verifying if the image has been stored in the filesystem using the Emulator (I'm developing for Android without a device).</p>
  
  <p>I have also tried wrapping the save event in an <code>if</code> tag, assuming that the output of <code>saveToFile()</code> is a boolean:</p>
  
  <pre><code>if(img.saveToFile(path, enums.ImageFormat.jpg)) console.log("success");
      else console.log("failure");
  </code></pre>
  
  <p>...however this also outputs nothing.</p>
  
  <h1>Question</h1>
  
  <p>How can I save the image from the URL to the device's local storage?</p>
  
  <p><em>References</em></p>
  
  <ul>
  <li><a href="http://www.nativescript.org" rel="nofollow noreferrer">Nativescript</a></li>
  <li><a href="https://docs.nativescript.org/cookbook/image-source#save-image-source-to-png-or-jpg-file" rel="nofollow noreferrer">image-source on Nativescript docs</a></li>
  <li><a href="http://docs.nativescript.org/api-reference/classes/_image_source_.imagesource.html" rel="nofollow noreferrer">ImageSource on Nativescript API docs</a></li>
  </ul>