- Home /
Download multiple files from server
Hello and thanks for checking this question!
I'm making a WebGL app and I need to download multiple files when the page loads.
Here is my code. It is working perfect for downloading a single file.
What should I change to make it download multiple files?
Any help is appreciated.
Thanks!
IEnumerator DownloadFileCo(string file_name, string decompressPath)
{
string url = "http://mywebsite.com/uploads/" + file_name + ".zip";
using (UnityWebRequest www = UnityWebRequest.Get(url))
{
yield return www.Send();
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
string savePath = string.Format("{0}/{1}.zip", Application.persistentDataPath, file_name);
System.IO.File.WriteAllBytes(savePath, www.downloadHandler.data);
Archiver.Decompress(savePath, decompressPath);
Debug.Log("Download complted");
}
}
}
public void DownlodFile()
{
//downloading test.zip from /uploads folder from server
StartCoroutine(DownloadFileCo("test", decompressPath: Application.persistentDataPath));
}
calling the coroutine multiple times should do it, it is not working?
It will work but it is now what I need. $$anonymous$$y files are in /uploads folder on server The files are uploaded by users so I don't know nothing about the file except that it is a .zip archive.
Anyway. I found a solution.
When user upload a zip to the server, make a thumbnail with the same name but add it to thumbnail.zip archive
Then download and decompress thumbnails.zip and create buttons for each thumbnail inside
And in the end when user will click on a thumbnail button I will call the above DownloadFile() method that will download my .zip? decompress it and open it for user.
Answer by Getsumi3 · Oct 29, 2019 at 07:12 PM
Ok. So I found a solution.
First of all I forgot to mention that downloaded file is a .zip archive that contains a folder inside and a thumbnail(that is a screenshot of the webgl window when user called Save() method).
Second, after some researces I realized that this isn't the best idea to download all files at once. It will be a huge overload on server that will end up with a slowdown or even crashes.
SOLUTION
When user upload a zip to the server, make a thumbnail with the same name but add it to thumbnails.zip archive
Then download and decompress thumbnails.zip and create buttons for each thumbnail inside
And in the end when user will click on a thumbnail button I will call the above DownloadFile() method that will download my .zip. decompress it, open it and let the user work with the content.
Can you tell the namespaces we have to use and what is archiver in archiver.decompress please its urgent!!!!
Hi. @rajatbhalla33
Archiver is an utility that I got from github: link --> https://github.com/LightBuzz/Archiver-Unity
As for namespaces here is the list:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using LightBuzz.Archiver;
using UnityEngine.Networking;
using System.Text;
Answer by jpgordon00 · Feb 09, 2021 at 04:49 AM
This project allows you to download any amount of files at a time. It has simple callbacks, progress calculation, cancellation and more . It uses UnityWebRequest to fulfill each download one at a time.
You can call it in code or use the MonoBehavior component. Check out the repository for detail on how to use it.
This repo can exists here now and can download files concurrently. Its very quick for scenarios where you need to download many files at once.
This project exists here now and allows you to download files concurrently. It's very quick for scoria's in which you need to download multiple files at a time.