- Home /
Downloading Large .Zip File from Web
I want to download a large .zip file from the web. I'll worry about extracting it later, but this is what I have:
string url = "https://www.blender.org/download/release/Blender3.0/blender-3.0.0-linux-x64.tar.xz/"
string filename = "blender-3.0.0-linux-x64.tar.xz"
IEnumerator GetCoroutine(string url, Action<string> onError, Action<string> onSuccess)
{
Debug.Log("Corutine Started");
using(UnityWebRequest site = UnityWebRequest.Get(url))
{
string saveurl = Application.dataPath+"/Game/"+filename;
site.downloadHandler = new DownloadHandlerFile(saveurl);
yield return site.SendWebRequest();
Debug.Log("Got Results");
if(site.result == UnityWebRequest.Result.ProtocolError)
{
onError(site.error);
} else {
onSuccess("sucess");
}
}
}
It works... Sorta - I get a corrupted file.
Answer by Bunny83 · Dec 05, 2021 at 11:31 PM
That's because the link you have here is not a download link. It's just a link to a website which loads tons of analytics and statistic scripts and most likely has a script that actually initiates the download. The actual download URL that gets started on my machine is this:
https://ftp.nluug.nl/pub/graphics/blender/release/Blender3.0/blender-3.0.0-linux-x64.tar.xz
Though this is an FTP mirror in the netherlands (since I'm located in the EU). When you open that webpage in your browser you may get a different mirror depending on your location. If that link you posted is the only one you can / want to use, you would need to parse the HTML page that is returned by your get request, extract the right url and then download that one.
When you use Firefox or Chrome you can open the developer tools and open the network tab. After that enter your original download link in the addressbar and see which requests are fireing and what each one returns.
So this has nothing to do with Unity. It's just the design of that "download link" which is not just a direct download link but a link to a website. So it's meant for tracking and to be opened in a browser that has javascript support.
Your answer
Follow this Question
Related Questions
Download progress is -1 forever. 2 Answers
Unity 5 Install failure for Example Project 0 Answers