Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to load Image called from URL dynamically.

Discussion in 'Scripting' started by DE_Hizral, Sep 30, 2021.

  1. DE_Hizral

    DE_Hizral

    Joined:
    Feb 21, 2020
    Posts:
    19
    Hello all,

    So base on the title above, I have a question regarding loading Image from URL, I mage to load a single image into my Unity without a problem using the getURL method with an image called "Image_01.jpg" that I place in my own server.

    So after that I did some testing to see if I could change the image that I called previously and change it dynamically by uploading another image into the server with the same name called "Image_01.jpg", so from my understanding the previous image will be replace with the new one and in Unity the gerUR code will stilll link with the same server link for the "image_01.jpg".

    But what happen is, my unity keep on uploading the old image that have been replace, and when I check the link it sometime does called back the previous image that been replace. What should I do now and?

    Thank you.
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,144
    Depending on the server, many of them can take a little bit to replace the image. Usually this is because of CDNs which have to distribute to many locations when you make a change. You'll not see this when you upload a brand new file, but generally I'll see changes within about an hour depending on what server I'm using.

    Another thing is to make sure you aren't caching the image or saving it when you download it.
     
    Bunny83 likes this.
  3. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,524
    Right, you should check the cache settings on your server. There are dirty hacks like adding a random number into the query string at the end of the url which makes the URL unique and the client and server is forced to refetch the actual image. However if every such request is cached, the cache would go up all the time. If you lost resources that should not be cached, this should be communicated properly.

    If you use an apache server or similar you could probably just do this with an .htaccess file like explained here, though use the correct file extension you want to use this rule for. If you use something else you have to look into how to set the correct Cache-Control headers for the response.
     
  4. DE_Hizral

    DE_Hizral

    Joined:
    Feb 21, 2020
    Posts:
    19
    Thank you all for your answer,

    I've tested out calling image using my friend server, and it work just fine. I think the server that i'm using have some sort of cache happening on the backend, and I myself not sure why this happen, But open a ticked to my server provider to get some answer.