Search Unity

Downloading a file with coroutine.

Discussion in 'Scripting' started by PulseHunter, Mar 9, 2016.

  1. PulseHunter

    PulseHunter

    Joined:
    Jul 31, 2013
    Posts:
    23
    Hi,

    When i try to download a file from out webserver, most of the time.
    It will only create/recive a 1kb file.

    Any idea why ?


    Code (CSharp):
    1. private IEnumerator FileDownloader(string FileLink,string name)
    2.     {
    3.         Debug.Log("current path " + path);
    4.         DownloadProgress = "";
    5.  
    6.         Debug.Log("Downloading from "+FileLink);
    7.         WWW www = new WWW(FileLink);    
    8.  
    9.         while (!www.isDone)
    10.         {
    11.             DownloadProgress = "Downloading " + (www.progress * 100).ToString() + "% ...";
    12.             Debug.Log(DownloadProgress);
    13.             yield return null;
    14.         }
    15.  
    16.                DownloadProgress = "100 % "+name;
    17.  
    18.                Debug.Log(DownloadProgress);
    19.  
    20.                File.WriteAllBytes(path + "//" + name + ".pdf",www.bytes);
    21.     }
     
    Last edited: Mar 9, 2016
  2. Teravisor

    Teravisor

    Joined:
    Dec 29, 2014
    Posts:
    654
    Please, use code tags when posting code.
    Is www .error!=null and what does it say if it is?
     
  3. PulseHunter

    PulseHunter

    Joined:
    Jul 31, 2013
    Posts:
    23
    Hi,

    I add the code tag now :)

    Nothing happen.
    It goes from 0% to 100% almost instant.

    Im trying to download a pdf.
     
    Last edited: Mar 9, 2016
  4. Patico

    Patico

    Joined:
    May 21, 2013
    Posts:
    886