# Save Image from URL

**URL:** <https://forums.fusetools.com/t/save-image-from-url/3999>\
**Category:** How-to Discussions\
**Created:** [April 20, 2016, 4:52am UTC](https://forums.fusetools.com/t/save-image-from-url/3999 "2016-04-20T04:52:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fbelluco](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/fbelluco/32/277_2.png) [@fbelluco](https://forums.fusetools.com/u/fbelluco)\
**Post date:** [April 20, 2016, 4:52am UTC](https://forums.fusetools.com/t/save-image-from-url/3999/1 "2016-04-20T04:52:26Z")

</div>

Is it possible to download an image from an URL and store into the device?

---

<div class="post-metadata">

**Author:** ![Kristian\_Hasselknipp](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/kristian_hasselknipp/32/549_2.png) [@Kristian\_Hasselknipp](https://forums.fusetools.com/u/Kristian_Hasselknipp)\
**Post date:** [April 25, 2016, 11:47pm UTC](https://forums.fusetools.com/t/save-image-from-url/3999/2 "2016-04-25T23:47:07Z")

</div>

Hi!

There is currently no out-of-the-box JS api for this, but you probably would be able to do it through foreign code if you don’t mind writing some code 🙂

You could take a look here ([https://www.fusetools.com/learn/uno#working-with-foreign-code](https://www.fusetools.com/learn/uno#working-with-foreign-code)) to get started.

---

<div class="post-metadata">

**Author:** ![Matti\_Tihverainen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/matti_tihverainen/32/684_2.png) [@Matti\_Tihverainen](https://forums.fusetools.com/u/Matti_Tihverainen)\
**Post date:** [January 3, 2018, 5:10pm UTC](https://forums.fusetools.com/t/save-image-from-url/3999/3 "2018-01-03T17:10:49Z")

</div>

Hello! Since this thread is one year old, is there a working JS api available for this? I was thinking of using Fetch to get the JPG file from the server, and then saving this binary data to the device using the Storage module. How can I reference the saved data to be used in the Image class?

---

<div class="post-metadata">

**Author:** ![Matti\_Tihverainen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/matti_tihverainen/32/684_2.png) [@Matti\_Tihverainen](https://forums.fusetools.com/u/Matti_Tihverainen)\
**Post date:** [January 3, 2018, 5:52pm UTC](https://forums.fusetools.com/t/save-image-from-url/3999/4 "2018-01-03T17:52:18Z")

</div>

Since I had a control over the backend I managed to solve this by creating a PHP script to encode the JPG file in to Base64 with this (image.php):

```auto
<?php $imagedata = file_get_contents("image.jpg"); echo base64_encode($imagedata); ?>

```

After that the Javascript:

```auto
<App>
  <JavaScript>

  var Observable = require("FuseJS/Observable");
  var ImageTools = require("FuseJS/ImageTools");
  var Storage = require("FuseJS/Storage");
  var myImage = Observable();

  fetch("http://www.domain.com/image.php", {
      method: "GET"
    }).then(function(response) {

      return response._bodyText;

    }).then(function(data) {

      console.log("Saving");

      Storage.write("image.jpg", data).then(function (success) {

        console.log("Saved");

        Storage.read("image.jpg").then(function(content) {

          console.log("Loading");

          ImageTools.getImageFromBase64(content).then(function(image) {

            console.log("Loaded");

            myImage.value = image.path;

          });

        });

      });

    });

  module.exports = {
    myImage : myImage
  };

  </JavaScript>
  <Image File="{myImage}" />
</App>

```

I’m not sure how to encode JPG’s to Base64 in JavaScript, but this works for me.
