- Home /
Content-length works for some file type and in different OS?
HI
I want to get the 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 the inspector.
So, I can get the 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 getting Content-length?
Best Regards and sorry for bad English!
Answer by mostafanastary · Sep 24, 2020 at 12:03 PM
So, After try over and over! I found we need to disable gzip on sever and I do it with .htaccess files
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Microsoft Visual C# Compiler error 0 Answers
Making Everything Public 0 Answers
How Can I get the mouse to Cycle Through Animations Each Time I click it? Please Help! 1 Answer