Search code examples
c#androidunity-game-enginecontent-length

Content-length works for some file type and in different OS?


I want to get length of my some type of file from my server like : .mp4 , .xml , .png , and custom file type .500 !

I printed length with C# code in unity with :

public class Tmp_ContentLength : MonoBehaviour {
    public List<string> urls = new List<string> ();


    void Start () {

        for (int i = 0; i < urls.Count; i++) {
            print (urls[i]);

            StartCoroutine (GetFileSize (urls[i],
                (size) => {
                   print ("File Size::> " + size);

                }));
        }
    }

    IEnumerator GetFileSize (string url, Action<Int32> result) {
        UnityWebRequest uwr = UnityWebRequest.Head (url);
        yield return uwr.SendWebRequest ();
        string size = uwr.GetResponseHeader ("Content-Length");

        if (uwr.isNetworkError || uwr.isHttpError) {
            print("Error While Getting Length: " + uwr.error);
            if (result != null)
                result (-1);
        } else {
            if (result != null)
                result (Convert.ToInt32 (size));
        }
    }
}

urls field fill with true Urls in inspector.

So, I can get length of all files in unity editor, but when I export .apk and run it, I will get print of .mp4 and .png , not .xml and .500(my custom file type ) .

1- Is there any issue or I,m wrong? 2- How can I enable Content-length header for .xml and my custom file type? 3- What is different between unity editor and android for get Content-length ?

Best Regards and sorry for bad English!


Solution

  • So, After try over and over! I found we need to disable gzip on sever and I do it with .htaccess files