|
@@ -62,69 +62,15 @@ public class FileBrowserController : MonoBehaviour, IPointerDownHandler
|
|
// Open file
|
|
// Open file
|
|
string[] paths = new string[0];
|
|
string[] paths = new string[0];
|
|
|
|
|
|
- // Open file with filter
|
|
|
|
- //var es = new[] {new ExtensionFilter("Image Files", "png", "jpg", "jpeg" )};
|
|
|
|
-
|
|
|
|
- //es = new[] {new ExtensionFilter("Image Files", "png", "jpg", "jpeg" )};
|
|
|
|
paths = StandaloneFileBrowser.OpenFilePanel($"Выбор изображения", "", "png,jpg", false);
|
|
paths = StandaloneFileBrowser.OpenFilePanel($"Выбор изображения", "", "png,jpg", false);
|
|
|
|
|
|
- //var paths = StandaloneFileBrowser.OpenFilePanel("Open File", "", extensions, true);
|
|
|
|
-
|
|
|
|
- // Open file async
|
|
|
|
- //StandaloneFileBrowser.OpenFilePanelAsync(name_view, "", es, false, (string[] paths) => {
|
|
|
|
- // if (paths.Length > 0)
|
|
|
|
- // {
|
|
|
|
- // StartCoroutine(OutputRoutine(new System.Uri(paths[0]).AbsoluteUri));
|
|
|
|
- // }
|
|
|
|
- //});
|
|
|
|
-
|
|
|
|
- //var paths = StandaloneFileBrowser.OpenFilePanel(name_view, "", "txt", true);
|
|
|
|
if (paths.Length > 0)
|
|
if (paths.Length > 0)
|
|
{
|
|
{
|
|
Debug.Log(paths[0]);
|
|
Debug.Log(paths[0]);
|
|
- //StartCoroutine(UpLoadUserData(new System.Uri(paths[0]).AbsoluteUri));
|
|
|
|
StartCoroutine(UpLoadUserData(paths[0]));
|
|
StartCoroutine(UpLoadUserData(paths[0]));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private IEnumerator OutputRoutine(string url)
|
|
|
|
- {
|
|
|
|
- //var loader = new WWW(url);
|
|
|
|
- Debug.Log($"file url pc {url}");
|
|
|
|
-
|
|
|
|
- var server_url = $"{Application.streamingAssetsPath}/Targets/{Path.GetFileName(url)}";
|
|
|
|
-
|
|
|
|
- Debug.Log($"file url server {server_url}");
|
|
|
|
- var request = UnityWebRequest.Get(url);
|
|
|
|
- yield return request.SendWebRequest();
|
|
|
|
- //yield return loader;
|
|
|
|
- if (!File.Exists(url))
|
|
|
|
- {
|
|
|
|
- while (!request.isDone)
|
|
|
|
- {
|
|
|
|
- yield return null;
|
|
|
|
- }
|
|
|
|
- if (!string.IsNullOrEmpty(request.error))
|
|
|
|
- {
|
|
|
|
- Debug.LogError("Error unpacking:" + request.error + " path: " + request.url);
|
|
|
|
- yield break; //skip it
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- if (!Directory.Exists(Path.GetDirectoryName(server_url)))
|
|
|
|
- {
|
|
|
|
- Directory.CreateDirectory(Path.GetDirectoryName(server_url));
|
|
|
|
- }
|
|
|
|
- File.WriteAllBytes(server_url, request.downloadHandler.data);
|
|
|
|
- Debug.Log($"success file load {server_url}");
|
|
|
|
- inputField.text = server_url;
|
|
|
|
- //could add to some kind of uninstall list?
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- yield return 0;
|
|
|
|
- //output.texture = loader.texture;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Отправка файла на сервер
|
|
/// Отправка файла на сервер
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -132,38 +78,34 @@ public class FileBrowserController : MonoBehaviour, IPointerDownHandler
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
IEnumerator UpLoadUserData(string url)
|
|
IEnumerator UpLoadUserData(string url)
|
|
{
|
|
{
|
|
- //var file = UnityWebRequest.Get(url);
|
|
|
|
- //yield return file;
|
|
|
|
Debug.Log(url);
|
|
Debug.Log(url);
|
|
-
|
|
|
|
WWWForm form = new WWWForm();
|
|
WWWForm form = new WWWForm();
|
|
- //form.AddBinaryData("file", file.downloadHandler.data);
|
|
|
|
-
|
|
|
|
- //var screenShotURL = URL_OF_SERVER_PHP_PAGE;
|
|
|
|
- //var bytes = Encoding.UTF8.GetBytes(url);
|
|
|
|
- //var form = new WWWForm();
|
|
|
|
-
|
|
|
|
- // string data = JsonUtility.ToJson(DataBaseManager.DataBase[username]);
|
|
|
|
- //WWWForm form = new WWWForm();
|
|
|
|
- //form.AddField("name", username);
|
|
|
|
- //form.AddField("data", data);
|
|
|
|
UnityWebRequest www;
|
|
UnityWebRequest www;
|
|
string file_name;
|
|
string file_name;
|
|
|
|
+ string php = "";
|
|
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
|
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
|
{
|
|
{
|
|
var deserialize = JsonConvert.DeserializeObject<List<urls>>(url);
|
|
var deserialize = JsonConvert.DeserializeObject<List<urls>>(url);
|
|
file_name = deserialize[0].file_name;
|
|
file_name = deserialize[0].file_name;
|
|
- byte[] bytes = Encoding.UTF8.GetBytes(deserialize[0].reader);
|
|
|
|
|
|
+ Debug.Log($"file image {file_name}");
|
|
|
|
+ byte[] bytes = Encoding.UTF8.GetBytes(deserialize[0].base64);
|
|
|
|
+ Debug.Log($"bytes {bytes.Length}");
|
|
form.AddBinaryData("file", bytes, deserialize[0].file_name);
|
|
form.AddBinaryData("file", bytes, deserialize[0].file_name);
|
|
- www = UnityWebRequest.Post($"{Application.streamingAssetsPath}/upload.php", form);
|
|
|
|
|
|
+ php = $"{Application.streamingAssetsPath}/upload.php";
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
file_name = Path.GetFileName(url);
|
|
file_name = Path.GetFileName(url);
|
|
- var bytes = File.ReadAllBytes(url);
|
|
|
|
- form.AddBinaryData("file", bytes, file_name);
|
|
|
|
- www = UnityWebRequest.Post($"http://dev.prmsys.net/positionviewer/StreamingAssets/upload.php", form);
|
|
|
|
|
|
+ using (FileStream fstream = File.OpenRead(url))
|
|
|
|
+ {
|
|
|
|
+ // преобразуем строку в байты
|
|
|
|
+ byte[] bytes = new byte[fstream.Length];
|
|
|
|
+ fstream.Read(bytes, 0, bytes.Length);
|
|
|
|
+ form.AddBinaryData("file", bytes, file_name);//{Path.GetExtension(url)}
|
|
|
|
+ php = $"http://dev.prmsys.net/positionviewer/StreamingAssets/upload.php";
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+ www = UnityWebRequest.Post(php, form);
|
|
yield return www.SendWebRequest();
|
|
yield return www.SendWebRequest();
|
|
if (www.isHttpError)
|
|
if (www.isHttpError)
|
|
Debug.Log(www.error);
|
|
Debug.Log(www.error);
|
|
@@ -179,7 +121,7 @@ public class FileBrowserController : MonoBehaviour, IPointerDownHandler
|
|
{
|
|
{
|
|
public string url { get; set; }
|
|
public string url { get; set; }
|
|
public string file_name { get; set; }
|
|
public string file_name { get; set; }
|
|
- public string reader { get; set; }
|
|
|
|
|
|
+ public string base64 { get; set; }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|