IEnumerator SaveData(UnityWebRequest request, DataSentToServerFunc callback = null) { yield return request.SendWebRequest(); // Get the actual filename string[] uri = request.url.Split('/'); string filename = uri[uri.Length-1]; bool couldBeSent = false; if (request.isNetworkError || request.isHttpError) { Debug.Log(string.Format("Couldn't upload file {0} due to: {1}", request.url, request.error)); } else { couldBeSent = true; } if (callback != null) callback(filename, couldBeSent); }
/// <summary> /// Sends the given string to the AssetServer and puts it into a file /// </summary> /// <param name="textToSend">A string representing the content of the file</param> /// <param name="filename">The file in which to put the contents. Can be prefixed by a folder-structure.</param> /// <param name="callback">Optional callback which will be called upon completing the upload</param> public void SendDataToServer(string textToSend, string filename, DataSentToServerFunc callback = null) { Debug.Log(string.Format("Asset Manager: Sending data to server: {0}...", filename)); UnityWebRequest req = UnityWebRequest.Put((string.Format("{0}/{1}", this.ServerAddress, filename)), textToSend); StartCoroutine(SaveData(req, callback)); }