I try to get the file size of an archive on GitHub, for example
https://github.com/UltraStar-Deluxe/songs-stream/archive/refs/heads/main.zip
Therefor, the following code runs in a coroutine:
using UnityWebRequest request = UnityWebRequest.Head(url);
Debug.Log("Before");
yield return request.SendWebRequest();
Debug.Log("After");
if (request.result
is UnityWebRequest.Result.ConnectionError
or UnityWebRequest.Result.ProtocolError)
{
Debug.LogError($"Error fetching size: {request.error}");
}
else
{
string contentLength = request.GetResponseHeader("Content-Length");
Debug.Log("contentLength: " + contentLength);
}
“Before” is always reached, but “After” is sometimes not reached immediately.
I see a warning in the console coming from request.SendWebRequest()
Redirect to https://codeload.github.com/UltraStar-Deluxe/songs-stream/zip/refs/heads/main expects a GET, but DownloadHandler is not set
What is this warning about? Does the HEAD request not follow redirects?
As it is now, the file size is obtained sometimes successfully and sometimes not.
Is there a better way to query the file size of an archive of a GitHub repo?