unity-game-engineserverunitywebrequest

not able to download file with size more than 63kb using UnityWebRequest


i am try to download asset bundle from an url but the request keep on cancelling after downloading 63kb. Can anyone explain to me why this may be happening?

My Code :

public IEnumerator DL()
{
    string downloadlink = "https://drive.google.com/file/d/1OGyrB4-MQfo-HVom9ENvV4dn312_wL4Q/view?usp=sharing";
    string filepath = Application.persistentDataPath + "/electroplatingNN";
    //Download
    UnityWebRequest dlreq = new UnityWebRequest(downloadlink);
    dlreq.downloadHandler = new DownloadHandlerFile(filepath);
    dlreq.timeout = 15;

    UnityWebRequestAsyncOperation op = dlreq.SendWebRequest();

    while (!op.isDone)
    {
        //here you can see download progress
        Debug.Log(dlreq.downloadedBytes / 1000 + "KB");

        yield return null;
    }

    if (dlreq.isNetworkError || dlreq.isHttpError)
    {
        Debug.Log(dlreq.error);
    }
    else
    {
        Debug.Log("download success");
    }

    dlreq.Dispose();

    yield return null;

}

Solution

  • As already mentioned in the comments the issue is not in the UnityWebrequest but rather Google Drive doesn't simply download your file as you expect.

    Instead the data you download is actually only the web page which would allow you to download it. If I simply open your file in a browser I get a page looking like this

    enter image description here

    where I now could download your file.


    There are packages like this or this which implement the necessary stuff for actually download files from Google Drive API in Unity.