Search Unity

WebGL large file upload

Discussion in 'Web' started by ihsan07, Nov 23, 2017.

  1. ihsan07

    ihsan07

    Joined:
    Mar 28, 2016
    Posts:
    17
    Hi folks!
    I have been trying to upload files to my WebGL build on runtime. My problem is not with codes. Everything seems to work great following this tutorial here. But whenever I try to send a larger than 1.6Mb file with Javascript to Unity with "SendMessage" function, "Stack overflow" error message appeared. So I sliced file into chunks before sending. It also works on small files but whenever file is larger than 1.6Mb, I get "Out of Memory" error message. Increasing memory size for WebGL builds didn't help at all. I appreciate any ideas.
     
  2. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    could you please be more specific? What are you sending via SendMessage?
     
  3. ihsan07

    ihsan07

    Joined:
    Mar 28, 2016
    Posts:
    17
    I read file in Javascript and encode it with base64 via FileReader.readAsDataURL() and I send the result string value with "SendMessage" function. I can get it in Unity if file size is lower than 1.6Mb but if it goes any higher it breaks as mentioned. There is a working WebGL here. It also gets files via Javascript. It also goes "Out of Memory" if uploaded file goes higher than mentioned limit.
     
  4. ihsan07

    ihsan07

    Joined:
    Mar 28, 2016
    Posts:
    17
    Any comments on subject, please? I will use WebGL as an user interface so achieving this is essential for me. I have been experimenting about on the subject nearly for a week now. Nothing worked so far.
     
  5. ihsan07

    ihsan07

    Joined:
    Mar 28, 2016
    Posts:
    17
    Why no comment?
     
    Last edited: Dec 2, 2017
  6. ihsan07

    ihsan07

    Joined:
    Mar 28, 2016
    Posts:
    17
    Well, I found out what I did wrong. :p My method was reading contents of text file in Javascript with FileReader and sending a large string in "Send Message" function. The problem with that is there is a limit how long strings can be in browsers, therefore errors. "URL.createObjectURL" javascript method creates a blob and sends its location in string so it works. The reason that example is not working, because it tries to render contents of text file and if it is too large, it goes out of memory. I assumed Javascript "FileReader" and "URL.createObjectURL" worked same as each other so I couldn't see problem.