Image by URL?

  1. 5 years ago

    ingurgite

    13 Jan 2019 User since 2018

    Hi,

    I would like to download an image and store it offline e.g in a database. I've tried the following but it returns a null object.

    var img = Image.open("https://images.sftcdn.net/images/t_app-cover-l,f_auto/p/ce2ece60-9b32-11e6-95ab-00163ed833e7/260663710/the-test-fun-for-friends-screenshot.jpg")
    Console.write(img)

    Thanks.

  2. marco

    31 Jan 2019 Administrator User since 2016

    Hi @ingurgite,
    the best way would be to use an ImageView.

    ImageView.url = "https://images.sftcdn.net/images/t_app-cover-l,f_auto/p/ce2ece60-9b32-11e6-95ab-00163ed833e7/260663710/the-test-fun-for-friends-screenshot.jpg";
    var img = ImageView.image;
    Console.write(img);
  3. ingurgite

    2 Mar 2019 User since 2018

    Hi @marco.

    I'm not sure I understand because this would imply displaying the image, which I do not want. I want to download images in the background and display them later. Is that possible in any way?

    Based on the documentation, it should be possible with the Image class: "func open(srcfile: Object): Object Initializes and returns the image object with the content of the source file. The source file can be an URL or a File object.".

    Thanks a lot.

  4. andrea

    4 Mar 2019 Administrator User since 2016

    Hi @ingurgite,
    the URL of the open method of the Image class refers to file URLs of local files.

    You can use the HTTPRequest class to download the image from the web (an example of how to use this class programmatically to download an image is described in the first example in the HTTPRequest Documentation ).
    When you have downloaded the image object, you can then save it to a local file with the FileManager class or to a SQLite Database to use it later.

or Sign Up to reply!