Search Unity

Uploading file to AWS, UnityWebRequest.uploadProgress works in editor but not iOS

Discussion in 'Multiplayer' started by J_P_, Dec 20, 2019.

  1. J_P_

    J_P_

    Joined:
    Jan 9, 2010
    Posts:
    1,027
    2018.4.13

    Code (CSharp):
    1.         byte[] bytes = System.IO.File.ReadAllBytes(path);
    2.         string signedUrl = url;
    3.         UnityWebRequest www = UnityWebRequest.Get(signedUrl);
    4.         www.SetRequestHeader("Content-Type", "video/mp4");
    5.      
    6.  
    7.         www.uploadHandler = (UploadHandler) new UploadHandlerRaw(bytes);
    8.         www.method = "PUT";
    9.  
    10.         www.SendWebRequest();
    11.         while (!www.isDone)
    12.         {          
    13.             callback(www.uploadProgress);
    14.             yield return null;
    15.         }
    uploadProgress returns either 0 or 1 on iOS -- in Editor it behaves as expected during upload.

    I've also tried using UnityWebRequest.Put() but same problem. Again, works in editor, not iOS -- haven't tried Android yet. I read it might be due to server not sending Content-Length in response headers, but GetResponseHeaders() fails until it's complete and Content-Length is there then. I tried to spoof Editor's user-agent but www.GetRequestHeader("User-Agent"); returns empty string.

    Ideas? Uploading big files so progress bar is definitely needed.