uploading/downloading files
parent
815707b8ad
commit
170731501f
|
|
@ -150,7 +150,8 @@ namespace VELConnect
|
|||
SetDeviceField(new Dictionary<string, object>
|
||||
{
|
||||
{ "current_app", Application.productName },
|
||||
{ "pairing_code", PairingCode }
|
||||
{ "pairing_code", PairingCode },
|
||||
{ "friendly_name", SystemInfo.deviceName },
|
||||
});
|
||||
|
||||
UpdateUserCount();
|
||||
|
|
@ -533,14 +534,43 @@ namespace VELConnect
|
|||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
HttpResponseMessage r = await new HttpClient().PostAsync(_instance.velConnectUrl + "/api/upload_file", requestContent);
|
||||
HttpResponseMessage r =
|
||||
await new HttpClient().PostAsync(_instance.velConnectUrl + "/api/upload_file", requestContent);
|
||||
string resp = await r.Content.ReadAsStringAsync();
|
||||
Dictionary<string, string> dict = JsonConvert.DeserializeObject<Dictionary<string,string>>(resp);
|
||||
Dictionary<string, string> dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(resp);
|
||||
successCallback?.Invoke(dict["key"]);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public static void DownloadFile(string key, Action<byte[]> successCallback = null)
|
||||
{
|
||||
_instance.StartCoroutine(_instance.DownloadFileCo(key, successCallback));
|
||||
}
|
||||
|
||||
private IEnumerator DownloadFileCo(string key, Action<byte[]> successCallback = null)
|
||||
{
|
||||
UnityWebRequest www = new UnityWebRequest(velConnectUrl + "/api/download_file/" + key);
|
||||
www.downloadHandler = new DownloadHandlerBuffer();
|
||||
yield return www.SendWebRequest();
|
||||
|
||||
if (www.result != UnityWebRequest.Result.Success)
|
||||
{
|
||||
Debug.Log(www.error);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Show results as text
|
||||
Debug.Log(www.downloadHandler.text);
|
||||
|
||||
// Or retrieve results as binary data
|
||||
byte[] results = www.downloadHandler.data;
|
||||
|
||||
successCallback?.Invoke(results);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void GetRequestCallback(string url, Action<string> successCallback = null,
|
||||
Action<string> failureCallback = null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "edu.uga.engr.vel.vel-connect",
|
||||
"displayName": "VEL-Connect",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"unity": "2019.1",
|
||||
"description": "Web-based configuration for VR applications",
|
||||
"keywords": [],
|
||||
|
|
@ -14,4 +14,4 @@
|
|||
"dependencies": {
|
||||
"com.unity.nuget.newtonsoft-json": "3.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue