Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Knowing WWW file download size before download it?

Discussion in 'iOS and tvOS' started by Juang3d, Jun 6, 2014.

  1. Juang3d

    Juang3d

    Joined:
    Sep 25, 2012
    Posts:
    87
    Hi there.

    I need to check if the local file is the same as the online file before download it, that way I will know if I have to update the file or not.

    Is there a way to do that?

    Cheers and thanks in advance!
     
  2. Joskym

    Joskym

    Joined:
    Oct 2, 2013
    Posts:
    39
    You could have a manifest on your web server that contains the version of the file. If the file online is more recent that the local, download it. You still have to call WWW but you don't have to download your all file again.(I assume it's a big file). BTW comparing the size of the files is not very secure. If you change something on the new file but it still have the same size, it will not work
     
  3. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,623
    you can also cheat a bit: we do expose WWW implementation in trampoline and we read headers in there - so you can tweak both server to send out something in headers and native impl to check for "version". But if you are not that comfortable with objc - just go with manifest - that should work just fine
     
  4. Juang3d

    Juang3d

    Joined:
    Sep 25, 2012
    Posts:
    87
    Thanks both, I have to stay as Unity native as possible because this app goes to ios and android.

    Yes, the manifest solution was one option, in fact I'm working with xml's so having some kind of comparisson between the old xml and the new xml could solve the problem, but I was wondering if there was a way to compare online files to local files without having to download them, and the size check was an idea, others were compare creation data and such things, but it's not possible, so i think I will have to work with xml data.

    Cheers and thanks!
     
  5. kart_ranger

    kart_ranger

    Joined:
    Sep 12, 2014
    Posts:
    2
    It is possible, check this example, it returned the file size and downloaded no data to the device.

    Code (CSharp):
    1. using (UnityWebRequest uwr = UnityWebRequest.GetTexture(uri))
    2. {                      
    3.     uwr.method = "HEAD";
    4.     yield return uwr.Send();
    5.  
    6.     Debug.LogError(uwr.GetResponseHeader("Content-Length"));
    7.     Debug.LogError(uwr.downloadedBytes);
    8. }
     
  6. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,722
    Like this, but there is a bit more efficient way to do it:
    https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest.Head.html
     
    geretti likes this.