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

Using LoadFromCacheOrDownload on a server that requries authorization

Discussion in 'Scripting' started by ScrappyRMH, Apr 22, 2013.

  1. ScrappyRMH

    ScrappyRMH

    Joined:
    Apr 11, 2011
    Posts:
    48
    I am using a server that requires a login and password. When using the WWW object I am using the WWWForm object to add the authorization header so that I can access the data. This works.

    But now I am trying to download asset bundles from the same server using LoadFromCacheOrDownload and am receiving "401 Authorization Required". I can't add headers to this call since that is not a parameter that can be passed with this function. Is there any way around this or is there a way to add these headers before the call?
     
  2. et_cloudcade

    et_cloudcade

    Joined:
    Jul 8, 2014
    Posts:
    8
    same here, looking for solution
     
  3. Yarogleck

    Yarogleck

    Joined:
    Dec 12, 2012
    Posts:
    3
    Same for me
     
  4. sirrus

    sirrus

    Joined:
    Jun 10, 2012
    Posts:
    250
  5. Kadaj

    Kadaj

    Joined:
    Jul 24, 2014
    Posts:
    19
    Did you find a workaround solution?
     
  6. sirrus

    sirrus

    Joined:
    Jun 10, 2012
    Posts:
    250
    We actually aren't using the LoadFromCacheOrDownload() in WebGL because of memory issues. The browser handles most of the caching for us currently though this is not ideal. We can apply request headers using the standard WWW calls and will soon be moving to the new UnityWebRequest system anyway.
     
  7. Kadaj

    Kadaj

    Joined:
    Jul 24, 2014
    Posts:
    19
    I see. In my case, I finally downloaded my datas with the WWW function (which allows me to use the header), then I saved my datas manually (using an array of bytes) in the cache memory :

    Code (CSharp):
    1. WWW www = new WWW (url, null, headers);
    2. yield return www;
    3.  
    4. if (!Directory.Exists(Application.persistentDataPath + "/Models/")) {
    5.     Directory.CreateDirectory(Application.persistentDataPath + "/Models/");
    6. }
    7.  
    8. byte[] bytes = www.bytes;
    9.  
    10. File.WriteAllBytes(Application.persistentDataPath + "/Models/" + modelName + ".unity3d", bytes);
    11.  
    12. AssetBundle bundle = AssetBundle.LoadFromFile(Application.persistentDataPath + "/Models/" + modelName + ".unity3d");
    13. yield return bundle;
    14.  
    15. modelDownloaded = bundle.LoadAsset(bundle.GetAllAssetNames()[0], typeof(GameObject)) as GameObject;
    16.  
    17. bundle.Unload (false);
    Hoping that it can help.