0
\$\begingroup\$
IEnumerator GetFileRequest(List<String> urlList, Action<List<UnityWebRequest>> callback)
{
    List<UnityWebRequest> reqList = new List<UnityWebRequest>();
    for (int i = 0; i < urlList.Count; i++)
    {
        using (UnityWebRequest req = UnityWebRequest.Get(urlList[i]))
        {
            req.downloadHandler = new DownloadHandlerFile(GetFilePath(urlList[i]));
            reqList.Add(req);
        }
    }
        yield return reqList;

    callback(reqList);
}

I'm using this code, all files get downloaded, but they seem to be corrupted ( I guess it's not completely downloaded). How do I complete the download without files getting corrupted?

\$\endgroup\$
1
  • \$\begingroup\$ What specific symptoms of corruption do you observe? What URLs and callbacks are you providing as input? \$\endgroup\$
    – DMGregory
    Aug 31, 2020 at 21:50

1 Answer 1

1
\$\begingroup\$

You can use this class to easily download multiple files at a time.

Below is an example of using this downloader (which uses UnityWebRequest) to download multiple files with callbacks. A full example is at the repo provided above:

GroupDownloader downloader = new GroupDownloader();
              
downloader.PendingURLS.Add("www.google.com/image/someimage.jpg");               
downloader.OnURIToFilename["www.google.com/image/someimage.jpg"] = "myimage.jpg";
downloader.AbandonOnFailure = false;

downloader.OnDownloadSuccess += (bool completed, string uri, string fileResultPath) => {
                       
                       Debug.Log("Success! " + (completed ? "COMPLETED : "INCOMPLETE") + ");
                       Debug.Log( "URI=" + uri + ", filePath=" + fileResultPath");
              }
              
downloader.OnDownloadFail += (bool completed, string uri, string fileResultPath) => {
                       
                       Debug.Log("Done downloading: " + completed");
                       Debug.Log("Failure. URI=" + uri + ", fileResultIfDownloaded=" + fileResultPath");
              }
              
/* Starts the download*/
downloader.Download();
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .