浏览代码

base64 jslib

Виктор Шейко 4 年之前
父节点
当前提交
dd27103170

+ 6 - 3
Assets/Scripts/Controllers/SendingFormController.cs

@@ -31,7 +31,7 @@ public class SendingFormController : MonoBehaviour
 
     }
 
-    public static IEnumerator PostRequest(string controller, string api, Dictionary<string, string> data, Action<string, Dictionary<string, string>> callback = null, Action<WWW> errorCallback = null)
+    /*public static IEnumerator PostRequest(string controller, string api, Dictionary<string, string> data, Action<string, Dictionary<string, string>> callback = null, Action<WWW> errorCallback = null)
     {
         WWWForm form = new WWWForm();
         //form.AddField("login", login);
@@ -71,7 +71,7 @@ public class SendingFormController : MonoBehaviour
             //else 
                 errorCallback(www);
         }
-    }
+    }*/
 
 
     IEnumerator PostRequest(string url, string json)
@@ -144,7 +144,10 @@ public class SendingFormController : MonoBehaviour
         {
             //Debug.Log(url);
             //var img = UnityWebRequestTexture.GetTexture(url); //, null, headers);
-
+            img.SetRequestHeader("Access-Control-Allow-Credentials", "true");
+            img.SetRequestHeader("Access-Control-Allow-Headers", "Accept, X-Access-Token, X-Application-Name, X-Request-Sent-Time");
+            img.SetRequestHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
+            img.SetRequestHeader("Access-Control-Allow-Origin", "*");
             yield return img.SendWebRequest();
             if (img.isNetworkError || img.isHttpError)
             {

+ 8 - 0
Assets/Scripts/Controllers/ToolsController.cs

@@ -188,11 +188,19 @@ public class ToolsController : MonoBehaviour
         old_btn_tools = Hammer;
     }
 
+    /// <summary>
+    /// old
+    /// </summary>
     public void OpenFileBrowser()
     {
        StartCoroutine(ShowLoadDialogCoroutine($"Выбор карты"));
     }
 
+    /// <summary>
+    /// old
+    /// </summary>
+    /// <param name="name_view"></param>
+    /// <returns></returns>
     IEnumerator ShowLoadDialogCoroutine(string name_view)
     {
         FileBrowser.SetFilters(true, new FileBrowser.Filter("Images", ".jpg", ".png"));

+ 20 - 21
Assets/StandaloneFileBrowser/Plugins/StandaloneFileBrowser.jslib

@@ -36,29 +36,28 @@ var StandaloneFileBrowserWebGLPlugin = {
         };
         fileInput.onchange = function (event) {
             // multiselect works
-            var urls = [];
-            var encoded;
+            var urls = [];  
+            
             for (var i = 0; i < event.target.files.length; i++) {
-                //urls.push(URL.createObjectURL(event.target.files[i]));
+                //urls.push(URL.createObjectURL(event.target.files[i]));                            
                 var reader = new FileReader();
-                //reader.readAsArrayBuffer(event.target.files[i]);
-               
-                var fileByteArrayLenth = 0;
-   
-    reader.onloadend = function(e) {                     
-        var buffer = e.target.result;
-        var uintArray = new Uint8Array(buffer);
-        /*for (var i = 0; i < uintArray.length; i++) {
-            fileByteArray.push(uintArray[i]);
-         }           */
-         fileByteArrayLenth=uintArray.length;
-    }   
-                urls.push({
-                    "url": URL.createObjectURL(event.target.files[i]),
-                    "file_name": event.target.files[i].name,
-                    "base64":  fileByteArrayLenth
-                });                
-            }
+                reader.readAsDataURL(event.target.files[i]);
+                var base64data;
+                reader.onload = function () {                    
+                    base64data = reader.result;
+                    console.log(base64data);                     
+                  };
+                  reader.onerror = function (error) {
+                    console.log('Error: ', error);
+                    base64data= error;
+                  };
+              
+                     urls.push({
+                        "url": URL.createObjectURL(event.target.files[i]),
+                        "file_name": event.target.files[i].name,
+                        "base64":  base64data
+                    });          
+                }
             // File selected
             SendMessage(gameObjectName, methodName, JSON.stringify(urls));