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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

upload progress

Discussion in 'Scripting' started by Kalidor, Dec 14, 2017.

  1. Kalidor

    Kalidor

    Joined:
    Sep 13, 2017
    Posts:
    14
    Hi!

    I want to get the upload progress.
    The code below works fine with downloading files (see commentaries), but not with uploading files.
    The while-loop is entered once, without a second condition check. Neither the error part in the while-loop is entered nor the part after the while-loop. The co-routine seems to hang up at line 35. For your information: "Test1", "Test2", "Test3" and "Test5" is shown in the console.

    unity application:
    Code (CSharp):
    1.      
    2.         // works!
    3.         // this.request = UnityWebRequest.Get(uri);
    4.         this.request = UnityWebRequest.Put(uri, data);
    5.  
    6.         this.request.SendWebRequest();
    7.  
    8.         Debug.Log("TEST1");
    9.  
    10.         while (!this.request.isDone)
    11.         {
    12.             Debug.Log("TEST2");
    13.          
    14.             // works!
    15.             // this.progress = this.request.downloadProgress;
    16.             this.progress = this.request.uploadProgress;
    17.  
    18.             Debug.Log("TEST3");
    19.  
    20.             if (this.request.isNetworkError || this.request.isHttpError)
    21.             {
    22.                 Debug.Log("TEST4");
    23.  
    24.                 this.requestRunning = false;
    25.  
    26.                 Debug.LogWarning(requestName + " request error: " + this.request.error);
    27.  
    28.                 this.DoRequestCallback();
    29.  
    30.                 yield break;
    31.             }
    32.  
    33.             Debug.Log("TEST5");
    34.  
    35.             yield return null;
    36.         }
    37.  
    38.         Debug.Log("TEST6");
    By the way: The server receives the data successfully. I'm using a tomcat server with Spring Boot.
    Currently the server only returns 0 (failed) or 1 (succeeded) as a byte array for internal use. Maybe there is additional data missing for a response?

    Any help?

    server side:

    Code (CSharp):
    1.  
    2.     @PutMapping("putFile")
    3.     public byte[] putFile(@RequestBody byte[] data, HttpServletRequest request)
    Edit: I also tried to return a ResponseEntity on the server side - with the same result.
     
    Last edited: Dec 15, 2017
  2. Kalidor

    Kalidor

    Joined:
    Sep 13, 2017
    Posts:
    14
    OK, i solved the yield problem (the game object was deleted to early...)
    Now the progress value is 0 or 1. Would be nice if i can get values between 0 and 1.
     
    Last edited: Dec 15, 2017
  3. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539