Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

DownloadHandlerFile downloads only the index.html file

Discussion in 'Scripting' started by Arcanebits, May 5, 2022.

  1. Arcanebits

    Arcanebits

    Joined:
    Dec 18, 2013
    Posts:
    108
    I need to download a file from server, used the example of unity found here:
    https://docs.unity3d.com/Manual/UnityWebRequest-CreatingDownloadHandlers.html DOWNLOADHANDLER

    Just moded thist two lines
    var uwr = new UnityWebRequest("https://unity3d.com/", UnityWebRequest.kHttpVerbGET);
    string path = Path.Combine(Application.persistentDataPath, "unity3d.html");

    to something like:
    var uwr = new UnityWebRequest("https://miserver/mydir/", UnityWebRequest.kHttpVerbGET);
    string path = Path.Combine(Application.persistentDataPath, "filename.txt");

    And the only thing I get is the content of index.html file with the filename.txt

    Anyone can help? its quite weird since its a copypaste from unitys code.
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,637
    To download file you need to provide URL to that file.
    UnityWebRequest is HTTP client, not web browser, it only downloads what given URL provides, unlike web browser, which looks into contents of downloaded file and does further downloads for images and script (and then execute those scripts which can do further downloads).
     
    Arcanebits likes this.
  3. Arcanebits

    Arcanebits

    Joined:
    Dec 18, 2013
    Posts:
    108
    I need to finish this line: ?
    var uwr = new UnityWebRequest("https://unity3d.com/", UnityWebRequest.kHttpVerbGET);

    and to put the name of file like:
    var uwr = new UnityWebRequest("https://unity3d.com/filename.txt", UnityWebRequest.kHttpVerbGET);

    Aldo
     
  4. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,637
    What file are you trying to download?
     
  5. Arcanebits

    Arcanebits

    Joined:
    Dec 18, 2013
    Posts:
    108
    filename.txt for an example, the name may even come a generated variable.
     
  6. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Not an example please, we are asking for the exact name of the file you are trying to download, and the URL. Did you create this file? If it is private information, then please send it in a private message.
     
  7. Arcanebits

    Arcanebits

    Joined:
    Dec 18, 2013
    Posts:
    108
    exact file name: frijol.txt
    exact path: https://multitoolstudios.com/frijoldirector
     
  8. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
  9. Arcanebits

    Arcanebits

    Joined:
    Dec 18, 2013
    Posts:
    108
  10. Arcanebits

    Arcanebits

    Joined:
    Dec 18, 2013
    Posts:
    108
  11. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Yes, now the file exists! Now you can download it. Just use that full URL.
     
  12. Arcanebits

    Arcanebits

    Joined:
    Dec 18, 2013
    Posts:
    108
    just have to tweak the example providsed in the docs right?
     
  13. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
  14. Arcanebits

    Arcanebits

    Joined:
    Dec 18, 2013
    Posts:
    108
    Thanks a lot for the help!
    Wow, it was MY mistake from the beginning. Thanks again Jeff.
     
    Last edited: May 6, 2022
    JeffDUnity3D likes this.