uploading/downloading files

dev
Anton Franzluebbers 2022-09-11 17:01:40 -04:00
parent 815707b8ad
commit 170731501f
2 changed files with 35 additions and 5 deletions

View File

@ -150,7 +150,8 @@ namespace VELConnect
SetDeviceField(new Dictionary<string, object> SetDeviceField(new Dictionary<string, object>
{ {
{ "current_app", Application.productName }, { "current_app", Application.productName },
{ "pairing_code", PairingCode } { "pairing_code", PairingCode },
{ "friendly_name", SystemInfo.deviceName },
}); });
UpdateUserCount(); UpdateUserCount();
@ -533,7 +534,8 @@ namespace VELConnect
Task.Run(async () => 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(); 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"]); successCallback?.Invoke(dict["key"]);
@ -541,6 +543,34 @@ namespace VELConnect
} }
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, public static void GetRequestCallback(string url, Action<string> successCallback = null,
Action<string> failureCallback = null) Action<string> failureCallback = null)
{ {

View File

@ -1,7 +1,7 @@
{ {
"name": "edu.uga.engr.vel.vel-connect", "name": "edu.uga.engr.vel.vel-connect",
"displayName": "VEL-Connect", "displayName": "VEL-Connect",
"version": "1.0.0", "version": "1.0.1",
"unity": "2019.1", "unity": "2019.1",
"description": "Web-based configuration for VR applications", "description": "Web-based configuration for VR applications",
"keywords": [], "keywords": [],