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

Problems uploading files to a server

Discussion in 'Scripting' started by xagustudios, Jun 18, 2021.

  1. xagustudios

    xagustudios

    Joined:
    Feb 6, 2017
    Posts:
    8
    Hi.

    I'm a bit confused on how I can upload files properly to a server. We need the option to upload user databases to the server so other users can download them

    I managed to upload files using wwwform and UnityWebRequest.Post method. It's quite easy to get the incoming stream and parse it to a file again in our server. The problem begins because we need to have control of the uploaded files ( such as database name, description, userID...) inserting them in a sql server database and linking that row with the uploaded file.

    We need so to upload some parameters in addition to the database file but i can't guess how to do it. Recently I discovered List<IMultipartFormSection> which seems can be useful for this task by adding one MultipartFormSection for each parameter ( ie: formData.Add(new MultipartFormDataSection("DBName", string)); ) and one for the file to upload (MultipartFormDataSection("File", byte[]) but the lack of information regarding how to handle the incoming data is driving me crazy. I have tried using the BynaryReader Class but It can not parse the incoming stream. I'm a bit lost... Using c# WCF server side.

    Any clue or suggestion?

    Thanks in advance
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,710
    Make a proper REST API web service that supports all the necessary components of your process, such as

    That way you can work entirely OUTSIDE of Unity with curl / Postman and your service until it is completely correct. You can even use other middleware such as Swagger to simulate and test everything.

    Once the service is completely and totally debugged, then access it from Unity.

    And when working in Unity with any Networking, UnityWebRequest, WWW, Postman, curl, WebAPI, etc:

    https://forum.unity.com/threads/using-unity-for-subscription-lists.1070663/#post-6910289

    https://forum.unity.com/threads/unity-web-request-acting-stupid.1096396/#post-7060150

    And setting up a proxy can be very helpful too, in order to compare traffic:

    https://support.unity.com/hc/en-us/articles/115002917683-Using-Charles-Proxy-with-Unity
     
    xagustudios likes this.
  3. xagustudios

    xagustudios

    Joined:
    Feb 6, 2017
    Posts:
    8
    Thanks. will try that approach.