Search Unity

[WebGL] How do I write JSON file on server?

Discussion in 'Scripting' started by Blarzek, Nov 12, 2017.

  1. Blarzek

    Blarzek

    Joined:
    Sep 4, 2017
    Posts:
    4
    Greetings!,
    I have my game on an external server (itch.io) and people can play it with a browser. In order to read a JSON file, I had changed File.ReadAllText(filePath)) for all this:

    Code (CSharp):
    1. IEnumerator ReadFileContent() {
    2.     if (filePath.Contains("://")) {
    3.         WWW www = new WWW(filePath);
    4.         yield return www;
    5.         json = www.text;
    6.     } else {
    7.         json = File.ReadAllText(filePath);
    8.     }
    9. }
    Then users make changes on that file and I have to save them. Now to write the file on the server I need to change File.WriteAllText(filePath, json) too.
    How can I do it? Thank you so much guys for the help.
     
    Last edited: Nov 22, 2017
  2. Blarzek

    Blarzek

    Joined:
    Sep 4, 2017
    Posts:
    4
    Could someone help me please? :(
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,697
    You would generally do this by creating a web endpoint on your server in order to handle authentication of the user connecting, etc., and then to accept the data (usually sent in a POST request) and write it to your server's filesystem or database.

    You can get started with the heroku toolbelt setup pretty easy and they have lots of examples in various languages like Python, Javascript, Ruby, etc.
     
  4. Blarzek

    Blarzek

    Joined:
    Sep 4, 2017
    Posts:
    4
    Thank you for reply, but I can't do that on the server. I would like to upload the game on itch.io site, or something similar.