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

Uploading local files to server with webgl

Discussion in 'WebGL' started by frankrs, Dec 14, 2016.

  1. frankrs

    frankrs

    Joined:
    Aug 29, 2009
    Posts:
    300
    I've been pulling out my hair trying to figure out how to upload local wav files from the users PC to a server through a WebGL build running in a browser. I bought a plugin that works great for uploading files when its in the editor, however as soon as its built foe WebGL and uploaded dosent work. Anyone know where I'm going wrong?
    Any help would be super great.

    Many thanks,
    Frank
     
  2. alexsuvorov

    alexsuvorov

    Unity Technologies

    Joined:
    Nov 15, 2015
    Posts:
    327
    Hello frankrs.

    There are two parts in this process: reading the file from the user drive and sending the data to the server. Sending the data to the server should work just fine in you case, however, reading the file is somewhat more complicated, because you can not access the user local drive directly from JavaScript, so standard approach wont work here.

    Hopefully the following example will help you modify your plugin and achieve the goal:
    https://forum.unity3d.com/threads/h...rddrive-into-a-webgl-app.380985/#post-2474594

    P.S. If your plugin does successfully read the file from the user drive (the file opening dialog appears and the selected file data reaches your WebGL application), but just does not send it to the server, then it might be a CORS related issue (for example, a POST request is being preflighted etc.). You should then provide additional information about the plugin and server setup.
     
    Last edited: Dec 14, 2016
  3. frankrs

    frankrs

    Joined:
    Aug 29, 2009
    Posts:
    300
    Thanks a bundle Alex. I'm confused though, where do I put in the header information for CORS? Does that go in the C# script around the WWWform method or in the PHP script I'm using to post data?
     
  4. jazzykhanx

    jazzykhanx

    Joined:
    Apr 11, 2018
    Posts:
    6
    Hi, Can i make it work for multiple files + can i upload the selected file to my server?
    thanks