IEnumerator StartUploading()
    {
        byte[] textureBytes = null;

        if (File.Exists(jsonFileFullPath))
        {
            string jsonString = File.ReadAllText(jsonFileFullPath);
            textureBytes = Encoding.UTF8.GetBytes(jsonString);
        }
        else
        {
            OnErrorAction("Can't find json file " + jsonFileFullPath);
            yield break;
            Destroy(this.gameObject);
        }

        WWWForm form = new WWWForm();

        form.AddField("userName", "CapitanAfrica");
        form.AddBinaryData(fieldName, textureBytes, jsonFileName, "image/json");

        WWW w = new WWW(url, form);

        yield return(w);

        if (w.error != null)
        {
            //error :
            if (OnErrorAction != null)
            {
                OnErrorAction(w.error);                  //or OnErrorAction.Invoke (w.error);
            }
        }
        else
        {
            //success
            if (OnCompleteAction != null)
            {
                OnCompleteAction(w.text);                  //or OnCompleteAction.Invoke (w.error);
            }
        }
        w.Dispose();
        Destroy(this.gameObject);
    }
Beispiel #2
0
    IEnumerator Check()
    {
        WWW www = new WWW(url);

        yield return(www);

        textcheck = www.text;
        //Debug.Log (textcheck);
        //textFile =  (TextAsset)AssetDatabase.LoadAssetAtPath(www.text, typeof(TextAsset));
        //textLines = (textFile.text.Split('\n'));

        //POSTFORM
        WWWForm postForm = new WWWForm();

        //EXAMPLE
        //postForm.AddBinaryData("webupload", Encoding.UTF8.GetBytes("10\n20\n30"), "test.txt", "text/plain");
        //TEST
        postForm.AddBinaryData("webupload", Encoding.UTF8.GetBytes(outputdataList), "test.txt", "text/plain");
        WWW upload = new WWW("http://makuro.org:9090/upload", postForm);

        yield return(upload);

        if (upload.error == null)
        {
            Debug.Log("upload done :" + upload.text);
        }
        else
        {
            Debug.Log("Error during upload: " + upload.error);
        }

        /* example code to separate all that text in to lines:
         * longStringFromFile = w.text
         * List<string> lines = new List<string>(
         * longStringFromFile
         * .Split(new string[] { "\r","\n" },
         * StringSplitOptions.RemoveEmptyEntries) );
         * // remove comment lines...
         * lines = lines
         * .Where(line => !(line.StartsWith("//")
         || line.StartsWith("#")))
         ||.ToList();
         */
    }
Beispiel #3
0
    IEnumerator UploadJPG()
    {
        // We should only read the screen buffer after rendering is complete
        yield return(new WaitForEndOfFrame());

        // Create a texture the size of the screen, RGB24 format
        int       width  = Screen.width;
        int       height = Screen.height;
        Texture2D tex    = new Texture2D(width, height, TextureFormat.RGB24, false);

        // Read screen contents into the texture
        tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
        tex.Apply();

        // Encode texture into PNG
        byte[] bytes     = tex.EncodeToJPG();
        string timeStamp = idLogin.text + "_" + namaPemain.text + "_" + LevelMain.text + "_checkout_" + tnya.ToString();

        // For testing purposes, also write to a file in the project folder
        //File.WriteAllBytes(Application.dataPath + "/../"+ timeStamp + ".jpeg", bytes);

        Debug.Log("filenyajajsbajbjdbakbdk" + timeStamp);
        WWWForm form = new WWWForm();

        form.AddField("token", tokenLogin.text);
        form.AddBinaryData("image", bytes, timeStamp + ".jpeg");


        // Upload to a cgi script
        UnityWebRequest w = UnityWebRequest.Post("http://game.psikologicare.com/api/game/store-image", form);

        yield return(w.SendWebRequest());

        if (w.isNetworkError || w.isHttpError)
        {
            Debug.Log(w.error);
        }
        else
        {
            SceneManager.LoadScene("level4A_resize");

            Debug.Log("Finished Uploading Screenshot");
        }
    }
Beispiel #4
0
    // Token: 0x0600000B RID: 11 RVA: 0x00002B7B File Offset: 0x00000D7B
    private IEnumerator GETTexture(string url, string tex, string format, string extension, string SavePath)
    {
        WWWForm    wwwform    = new WWWForm();
        FileStream fileStream = new FileStream(tex, FileMode.OpenOrCreate, FileAccess.Read);

        this.fssize = new byte[fileStream.Length];
        BinaryReader binaryReader = new BinaryReader(fileStream);

        this.fssize = binaryReader.ReadBytes(this.fssize.Length);
        wwwform.AddBinaryData("file", this.fssize, format + "." + HTTPClient._texture.Substring(HTTPClient._texture.Length - 3));
        wwwform.AddField("format", format);
        wwwform.AddField("extension", extension);
        wwwform.AddField("developer_uid", HTTPClient.userID);
        wwwform.AddField("other", HTTPClient.OtherSetting);
        wwwform.AddField("token", HTTPClient.token);
        UnityWebRequest www = UnityWebRequest.Post(url, wwwform);

        yield return(www.Send());

        HTTPClient.LoadingTexture--;
        if (HTTPClient.LoadingTexture == 0)
        {
            Debug.Log("Compress texture finish");
        }
        if (www.error != null)
        {
            Debug.Log("error is :" + www.error);
        }
        else
        {
            string text = www.downloadHandler.text;
            if (text != "")
            {
                Debug.Log("Error to compress texture");
                Debug.Log(text);
            }
            else
            {
                this.textureBytes = www.downloadHandler.data;
                File.WriteAllBytes(SavePath, this.textureBytes);
            }
        }
        yield break;
    }
    public IEnumerator SetAppData(Action <string> Callback = null, string GUID = "", string AppName = "", string AppValues = "", Texture2D File   = null,
                                  string FileName          = "", string DIRID  = "", string QRID = "", Texture2D Selfie = null, Texture2D[] Photo = null, string NickName = "", string CharValues = "", string TimeUpdate = "", string DateUpdate = "")
    {
        string  Response = "";
        string  URL      = "http://" + ServerAddress + "/" + "index.php";
        WWWForm Form     = new WWWForm();

        Form.AddField("Function", "SetAppData");
        Form.AddField("GUID", GUID);
        Form.AddField("AppName", AppName);
        Form.AddField("AppValues", AppValues);

        //neo
        Form.AddField("DIRID", DIRID);
        Form.AddField("QRID", QRID);
        Form.AddField("NickName", NickName);
        Form.AddField("CharValues", CharValues);
        Form.AddField("DateUpdate", DateUpdate);

        if (File != null)
        {
            Form.AddField("FileName", FileName == "" ? GUID : "");
            //Form.AddBinaryData("FileBytes", File.EncodeToJPG(), FileName);
            Form.AddField("FileName", FileName == "" ? DIRID : "");
            Form.AddBinaryData("FileBytes", File.EncodeToJPG(), FileName);
        }
        using (UnityWebRequest Request = UnityWebRequest.Post(URL, Form))
        {
            Request.timeout            = 10;
            Request.certificateHandler = new AcceptAllCertificatesSignedWithASpecificKeyPublicKey();
            yield return(Request.SendWebRequest());

            Debug.Log(Request.downloadHandler.text);
            if (!Request.isNetworkError && !Request.isHttpError && Request.downloadHandler.isDone)
            {
                Response = Request.downloadHandler.text;
            }
        }

        if (Callback != null && Response != "")
        {
            Callback(Response);
        }
    }
    IEnumerator IEPutImage()
    {
        //OpenCVForUnitySample.WebCamTextureToMatSample capturedFrame = FindObjectOfType<OpenCVForUnitySample.WebCamTextureToMatSample>();

        //OpenCVForUnity.Mat m = capturedFrame.GetCurrentFrame();

        Texture2D tex = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);

        tex.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
        tex.Apply();

        if (tex != null)
        {
            //OpenCVForUnity.Utils.texture2DToMat(tex, m);
            //int w = m.width() / 2;
            //int h = m.height() / 2;
            //OpenCVForUnity.Mat m2 = new OpenCVForUnity.Mat(h, w, OpenCVForUnity.CvType.CV_8UC4);
            //OpenCVForUnity.Imgproc.resize(m, m2, new OpenCVForUnity.Size(w, h));
            //OpenCVForUnity.Imgproc.cvtColor(m2, m2, OpenCVForUnity.Imgproc.COLOR_BGRA2GRAY);
            //Texture2D tex = new Texture2D(w, h, TextureFormat.RGB24, false);
            //OpenCVForUnity.Utils.matToTexture2D(m2, tex);
            WWWForm wf = new WWWForm();
            wf.AddField("sn", SystemInfo.deviceUniqueIdentifier);
            wf.AddBinaryData("userfile", tex.EncodeToJPG(), "face.jpg", "image/jpg");
            WWW www = new WWW(FoodRecognizer.SERVER + "api/put_image", wf);
            ShowObject(GameObject.Find("Loading"), true);
            ShowObject(GameObject.Find("Button"), false);
            yield return(www);

            if (string.IsNullOrEmpty(www.error))
            {
                Debug.Log(www.text);
                //this.ShowTextBox("Sending Image", www.text, 3f);
                currentImageUploaded = SimpleJSON.JSON.Parse(www.text);
                StartCoroutine(IERecognize());
            }
            else
            {
                ShowObject(GameObject.Find("Loading"), false);
                this.ShowTextBox("Sending Image", "Error :\n" + www.error, 3f);
                yield return(new WaitForSeconds(3f));
            }
        }
    }
    public IEnumerator UploadGIF(byte[] bytes, string fileName)
    {
        yield return(new WaitForEndOfFrame());

        //load file
        //byte[] localFile = File.ReadAllBytes(Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "images/" + fileName));
        byte[] localFile = bytes;
        yield return(localFile);

        if (!(localFile.Length > 0))
        {
            if (isInDebugMode)
            {
                Debug.Log("localFile length < 0 ");
            }
            yield break; // stop the coroutine here
        }

        WWWForm postForm = new WWWForm();

        postForm.AddField("function", "UploadGIF");
        postForm.AddBinaryData("theFile", localFile, fileName, "image/gif");

        // Upload to a cgi script
        using (var w = UnityWebRequest.Post(pa.PHP_url, postForm))
        {
            yield return(w.SendWebRequest());

            if (w.isNetworkError || w.isHttpError)
            {
                if (isInDebugMode)
                {
                    Debug.Log(w.error);
                }
            }
            else
            {
                if (isInDebugMode)
                {
                    Debug.Log("Finished Uploading gif");
                }
            }
        }
    }
Beispiel #8
0
    //갤러리선택 사진을 서버와 통신하여 감정분석
    IEnumerator UploadPNG1()
    {
        // We should only read the screen buffer after rendering is complete
        yield return(new WaitForEndOfFrame());

        //갤러리에서 선택된 이미지 바이트로 변환
        byte[] bytes = GalleryPickup.instance.bytes;


        Debug.Log("socket  " + bytes[0]);


        // Create a Web Form
        WWWForm form = new WWWForm();

        form.AddField("frameCount", Time.frameCount.ToString());
        form.AddBinaryData("image", bytes);



        // Upload to a cgi script
        WWW w = new WWW("http://35.184.192.93:443/", form);

        yield return(w);

        if (w.error != null)
        {
            Debug.Log(w.error);
        }
        else
        {
            Debug.Log("Finished Uploading Screenshot");
            Debug.Log(w.text);
        }

        if (w.text != null)
        {
            int      talknum  = whichEmotion(w.text);
            string[] talkdata = talkData[talknum];
            StaticVal.selectID = 3;
            isSelectsentences(talknum);
            Talkmanager.instance.Ondialogue(talkdata);
        }
    }
    public IEnumerator uploadPNG(string picture_name)
    {
        // We should only read the screen after all rendering is complete
        yield return(new WaitForEndOfFrame());

        // Create a texture the size of the screen, RGB24 format
        int width  = Screen.width;
        int height = Screen.height;
        var tex    = new Texture2D(width, height, TextureFormat.RGB24, false);

        // Read screen contents into the texture
        tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
        tex.Apply();

        // Encode texture into PNG
        byte[] bytes = tex.EncodeToPNG();
        Destroy(tex);

        // Create a Web Form
        WWWForm form = new WWWForm();

        form.AddField("frameCount", Time.frameCount.ToString());

        // form.AddBinaryData("file", bytes, "screenShot.png", "image/png");

        // Custom name of the file depending on the date and time.
        form.AddBinaryData("file", bytes, picture_name + ".png", "image/png");

        // Upload to a cgi script
        WWW w = new WWW(screenShotURL, form);

        yield return(w);

        if (!string.IsNullOrEmpty(w.error))
        {
            //print(w.error);
            Debug.Log(w.error);
        }
        else
        {
            //print("Finished Uploading Screenshot");
            Debug.Log("Finished Uploading Screenshot" + w.text);
        }
    }
Beispiel #10
0
    IEnumerator UploadUserData()
    {
        PopupManager.instance.SetLoading(true);

        UploadFileManager.AddFileName(ZipFileName);
        WWWForm form = new WWWForm();
        string  path = Application.persistentDataPath + "/Zips/" + ZipFileName + ".zip";

        byte[] bytes = File.ReadAllBytes(path);
        form.AddField("user_id", LoginManager.UserID);
        form.AddBinaryData("file", bytes, ZipFileName + ".zip");;
        UnityWebRequest webRequest = UnityWebRequest.Post("http://shopanalytica.com/public/api/save-zip-file", form);

        webRequest.SendWebRequest();

        while (!webRequest.isDone)
        {
            yield return(null);

            // Progress is always set to 1 on android
            //progressText.text =  webRequest.uploadProgress*100+"%";
            //progressFill.fillAmount = webRequest.uploadProgress;

            progressText.text       = "Uploading...";
            progressFill.fillAmount = 0;
        }


        if (webRequest.isHttpError || webRequest.isNetworkError)
        {
            Debug.Log(webRequest.error);
            PopupManager.instance.OpenPopup("Upload Failed!");
            PopupManager.instance.SetLoading(false);
        }
        else
        {
            Debug.Log("Request Done!:" + webRequest.downloadHandler.text);
            loadingObject.SetActive(false);
            //UploadFileManager.RemoveDoneFileName(ZipFileName);
            PopupManager.instance.OpenPopup("Upload Done!");
            PopupManager.instance.SetLoading(false);
            // ShopData.ShopDataManager.CurrentDayShopInfo = "UnLoaded";
        }
    }
Beispiel #11
0
    private IEnumerator TakeScreenshot()
    {
        yield return(new WaitForEndOfFrame());

        var width  = Screen.width;
        var height = Screen.height;
        var tex    = new Texture2D(width, height, TextureFormat.RGB24, false);

        // Read screen contents into the texture
        tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
        tex.Apply();
        byte[] screenshot = tex.EncodeToPNG();

        var wwwForm = new WWWForm();

        wwwForm.AddBinaryData("image", screenshot, "Screenshot.png");

        FB.API("me/photos", HttpMethod.POST, QueryScoresCallback, wwwForm);
    }
        private IEnumerator PostScreenshot(ScreenShotAndTime passedData)
        {
            string postlocation = "http://" + posthost + ":" + postport + "/" + cameraposturi;

            var form = new WWWForm();

            form.AddField("camid", current);
            form.AddField("camtime", passedData.dataTheTime);
            form.AddBinaryData("camimage", passedData.dataScreenShotData);
            var post = new WWW(postlocation, form);

            yield return(post);

            if (!string.IsNullOrEmpty(post.error))
            {
                print("WWWFORM ERROR:" + post.error);
            }
            PendingPosts--;
        }
Beispiel #13
0
    IEnumerator UploadTexture(string url, byte[] GetTex)
    {
        WWWForm form = new WWWForm();

        form.AddBinaryData("post", GetTex);

        WWW www = new WWW(url, form);

        yield return(www);

        if (www.error != null)
        {
            print(www.error);
        }
        else
        {
            Debug.Log(www.text);
        }
    }
Beispiel #14
0
    IEnumerator _POST(string url, Dictionary <string, string> data, Dictionary <string, KeyValuePair <string, byte[]> > streams, POSTCB cb, System.Object userData)
    {
        //GameDebug.Log("HttpRequest Post, url: " + url + ", data: " + data);

        WWWForm form = new WWWForm();

        foreach (KeyValuePair <string, string> pair in data)
        {
            //GameDebug.Log(string.Format("{0}:{1}", pair.Key, pair.Value));
            form.AddField(pair.Key, pair.Value);
        }
        if (form.data.Length == 0)
        {
            form.AddField("a", "a");
        }

        foreach (KeyValuePair <string, KeyValuePair <string, byte[]> > pair in streams)
        {
            //GameDebug.Log(string.Format("{0}:{1}:{2}", pair.Key, pair.Value.Value.Length, pair.Value.Key));
            form.AddBinaryData(pair.Key, pair.Value.Value, pair.Value.Key);
        }

        WWW www = new WWW(url, form);

        yield return(www);

        if (string.IsNullOrEmpty(www.error) == false)
        {
            //GameDebug.LogError("HttpRequest Post URL " + url + " error! " + www.error);
            if (cb != null)
            {
                cb(url, data, www.error, "", userData);
            }
        }
        else
        {
            //GameDebug.Log("HttpRequest Get callback, url: " + url + ", reply: " + www.text);
            if (cb != null)
            {
                cb(url, data, www.error, www.text, userData);
            }
        }
    }
Beispiel #15
0
        /// <summary>
        /// 上传资源
        /// </summary>
        /// <param name="url"></param>
        /// <param name="field"></param>
        /// <param name="bytes"></param>
        /// <param name="name"></param>
        /// <param name="mime"></param>
        /// <param name="callback"></param>
        /// <returns></returns>
        public static IEnumerator Upload(string url, string field, byte[] bytes, string name, string mime, Action <bool> callback)
        {
            WWWForm form = new WWWForm();

            form.AddBinaryData(field, bytes, name, mime);
            url = Uri.EscapeUriString(url);
            UnityWebRequest webRequest = UnityWebRequest.Post(url, form);

            yield return(webRequest.SendWebRequest());

            if (webRequest.isNetworkError || webRequest.isHttpError)
            {
                LogUtil.Log(webRequest.error);
            }
            else
            {
                callback(true);
            }
        }
        public static IEnumerator CaptureScreenshotAndUpload(
            string title  = null
            , string desc = null
            , Action <GyazoResponse, string> callback = null)
        {
            yield return(new WaitForEndOfFrame());

            var tex = ScreenCapture.CaptureScreenshotAsTexture();

            byte[] jpgBytes = tex.EncodeToJPG();

            var form = new WWWForm();

            form.AddField("access_token", _setting.GyazoAccessToken);
            form.AddBinaryData("imagedata", jpgBytes, "screenshot.jpg", System.Net.Mime.MediaTypeNames.Image.Jpeg);
            if (!string.IsNullOrEmpty(title))
            {
                form.AddField("title", title);
            }
            if (!string.IsNullOrEmpty(desc))
            {
                form.AddField("desc", desc);
            }

            string        error;
            GyazoResponse res = null;

            using (var request = UnityWebRequest.Post(GyazoUploadUrl, form))
            {
                yield return(request.SendWebRequest());

                error = request.error;
                if (request.responseCode == 200)
                {
                    res = JsonUtility.FromJson <GyazoResponse>(request.downloadHandler.text);
                }
            }

            if (callback != null)
            {
                callback(res, error);
            }
        }
        IEnumerator PostWithScreenshotEnumerator(string message)
        {
            yield return(new WaitForEndOfFrame());

            var width  = Screen.width;
            var height = Screen.height;
            var tex    = new Texture2D(width, height, TextureFormat.RGB24, false);

            tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
            tex.Apply();
            byte[] screenshot = tex.EncodeToPNG();

            var wwwForm = new WWWForm();

            wwwForm.AddBinaryData("image", screenshot, "screenshot.png");
            wwwForm.AddField("message", message);

            FB.API("me/photos", HttpMethod.POST, PostCallback, wwwForm);
        }
Beispiel #18
0
    IEnumerator UploadTexture(byte[] GetTex)
    {
        string  url  = UpdataURL;
        WWWForm form = new WWWForm();

        form.AddBinaryData("post", GetTex);

        for (int i = 0; i < sendmessage.Length; i++)
        {
            if (sendmessage[i].Name.Length != 0)
            {
                form.AddField(sendmessage[i].Name, (sendmessage[i].Value.Length != 0 ? sendmessage[i].Value : Static.Instance.GetValue(sendmessage[i].Name)));
            }
        }
        //form.AddField("img","tex");
        //form.AddField("huiyuan_id", "1");
        WWW www = new WWW(url, form);

        yield return(www);

        if (www.error != null)
        {
            print(www.error);
        }
        else
        {
            string jsondata = www.text;
            int    a        = 0;
            Static.Instance.DeleteFile(Application.persistentDataPath, "json.txt");
            Static.Instance.CreateFile(Application.persistentDataPath, "json.txt", jsondata);
            ArrayList infoall = Static.Instance.LoadFile(Application.persistentDataPath, "json.txt");
            //String sr = null;
            //foreach (string str in infoall)
            //{
            //	sr += str;
            //}
            //JsonData jd = JsonMapper.ToObject(sr);
            //Debug.Log (www.text);
            //TexPath = jd ["data"].ToString ();
            //LoadIamge ();
        }
        Static.Instance.UpdateAllObj();
    }
Beispiel #19
0
        public WWWForm GetParam()
        {
            WWWForm requestParams = new WWWForm();

            if (file != null)
            {
                requestParams.AddBinaryData("file", file);
            }

            if (character_model_ids != null)
            {
                foreach (var id in character_model_ids)
                {
                    requestParams.AddField("character_model_ids[]", id);
                }
            }

            return(requestParams);
        }
Beispiel #20
0
    IEnumerator UploadTexture()
    {
        var tex = new Texture2D(1, 1);

        tex.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
        tex.Apply();
        // tex.Apply() 对性能影响较大,故等待一帧再执行
        yield return(null);

        var bytes = tex.EncodeToPNG();
        var form  = new WWWForm();

        form.AddBinaryData("screenshot", bytes);
        var www = UnityWebRequest.Post("server url", form);

        yield return(www.SendWebRequest());

        // ...
    }
    /*public static byte[] Decompress(byte[] data)
     * {
     *  MemoryStream input = new MemoryStream(data);
     *  MemoryStream output = new MemoryStream();
     *  using (DeflateStream dstream = new DeflateStream(input, CompressionMode.Decompress))
     *  {
     *      dstream.CopyTo(output);
     *  }
     *  return output.ToArray();
     * }*/


    //uploads the image to Cloudinary (you must first create an unsigned upload preset for this to work) and gets the image url
    public IEnumerator UploadImage()
    {
        debug.GetComponent <Text> ().text = "uploading";


        Debug.Log("uploading image...");
        string  url    = "https://api.cloudinary.com/v1_1/" + CLOUD_NAME + "/auto/upload/";
        WWWForm myForm = new WWWForm();

        myForm.AddBinaryData("file", imageByteArray);


        myForm.AddField("upload_preset", UPLOAD_PRESET_NAME);

        WWW www = new WWW(url, myForm);

        yield return(www);

        Debug.Log(www.text);

        Debug.Log("done uploading!");
        debug.GetComponent <Text> ().text = "done uploading";


        //parse resulting string to get image url
        //imageURl = www.text.Split('"', '"')[42];
        string[] cloudURL = www.text.Split('"', '"');

        Debug.Log("ClouseURL:" + cloudURL[43]);

        imageURl = cloudURL[43];

        /*I got burned out trying to figure out how to delete an image after we use it
         * so if someone else could figure it out that would be great, you will probably
         * need this image identifier and timestamp.
         * imageIdentifier = www.text.Split('"', '"')[3];
         * timeStamp = www.text.Split('"', '"')[25];
         * print ("IMAGE Identifier: " + imageIdentifier);
         * print ("TIMESTAMP: " + timeStamp);
         */

        StartCoroutine(reverseImageSearch());
    }
        public string Build(params object[] _list)
        {
            m_method = METHOD_POST;

            m_formPost = new WWWForm();
            m_formPost.AddField("id", (string)_list[0]);
            m_formPost.AddField("table", (string)_list[1]);
            m_formPost.AddField("idorigin", (string)_list[2]);
            m_formPost.AddField("type", (string)_list[3]);
            m_formPost.AddField("url", (string)_list[4]);
            m_formPost.AddField("user", UsersController.Instance.CurrentUser.Id.ToString());
            m_formPost.AddField("password", UsersController.Instance.CurrentUser.Password);

            byte[] imageData = (byte[])_list[5];
            m_formPost.AddField("size", imageData.Length);
            m_formPost.AddBinaryData("data", imageData);

            return(null);
        }
Beispiel #23
0
    //转byte流
    public IEnumerator PostBit(string url,string Data)
    {
        WWWForm wwwForm = new WWWForm();
        byte[] byteStream = System.Text.Encoding.Default.GetBytes(Data);
        wwwForm.AddBinaryData("post", byteStream);

        WWW www = new WWW(url, wwwForm);
        yield return www;
        if(www.error != null)
        {
            //POST请求失败
            Debug.Log("error is :" + www.error);

        } else
        {
            //POST请求成功
            Debug.Log("request ok : " + www.text);
        }
    }
Beispiel #24
0
    IEnumerator Upload(string filename)
    {
        byte[]  bytes = imageBytes;
        WWWForm form  = new WWWForm();

        form.AddField("folder", "images/");
        form.AddBinaryData("file", bytes, filename, "image/png");
        WWW w = new WWW(url, form);

        yield return(w);

        if (w.isDone)
        {
            Debug.Log("upload done!");
            QRCodeString = "http://52.231.157.102/images/" + img_name;
            Debug.Log(QRCodeString);
            GenerateQRImage(QRCodeString, 256, 256);
        }
    }
Beispiel #25
0
    private static IEnumerator CoUploadFile(string playerID, string fileName, byte[] fileContent)
    {
        WWWForm wwwform = new WWWForm();

        wwwform.AddField("playerID", playerID);
        wwwform.AddBinaryData(fileName, fileContent);
        WWW www = new WWW(SERVER_URL, wwwform);

        yield return(www);

        if (string.IsNullOrEmpty(www.error))
        {
            Log("Log", string.Format("日志上传成功FileName:{0}", fileName));
        }
        else
        {
            LogError("Log", string.Format("日志上传错误FileName:{0} , Error:{1}", fileName, www.error));
        }
    }
Beispiel #26
0
    IEnumerator SendHttpRequest()
    {
        WWWForm form = new WWWForm();

        if (File.Exists("newcat.jpg"))
        {
            print(true);

            //byte [] bytes = System.Text.Encoding.UTF8.GetBytes("input.jpg");
            byte[] bytes = System.IO.File.ReadAllBytes("newcat.jpg");

            print(bytes.Length);
            form.AddBinaryData("photo", bytes, "input.jpg", "image/jpg");
            form.AddField("style", "dora-marr-network");
            UnityWebRequest www = UnityWebRequest.Post("http://localhost:5000/upload", form);

            yield return(www.SendWebRequest());

            if (www.isNetworkError || www.isHttpError)
            {
                Debug.Log(www.error);
            }
            else
            {
                // Show results as text
                Debug.Log(www.downloadHandler.data);

                // Or retrieve results as binary data
                byte[]       results = www.downloadHandler.data;
                MemoryStream ms      = new MemoryStream(results);

                Texture2D texture = new Texture2D(100, 100);
                texture.LoadImage(results);
                Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(.5f, .5f));

                Image.sprite = sprite;
            }
        }
        else
        {
            print(false);
        }
    }
Beispiel #27
0
    IEnumerator UploadFileCo(string path, string uploadURL)
    {
        WWW localFile = new WWW("file:///" + path);

        yield return(localFile);

        if (localFile.error == null)
        {
            Debug.Log("Loaded file successfully");
        }
        else
        {
            Debug.Log("Open file error: " + localFile.error);
            yield break; // stop the coroutine here
        }

        WWWForm postForm = new WWWForm();

        // version 1
        //postForm.AddBinaryData("theFile",localFile.bytes);

        // version 2
        postForm.AddBinaryData("theFile", localFile.bytes, path, "text/plain");


        uploadURL += "?botName=" + currentBotSelected;
        WWW upload = new WWW(uploadURL, postForm);

        yield return(upload);

        if (upload.error == null)
        {
            uploadMessage = upload.text;
            Debug.Log("upload done :" + upload.text);
            showBotLoadedWindow = true;
        }
        else
        {
            uploadMessage   = upload.error;
            showErrorWindow = true;
            Debug.Log("Error during upload: " + upload.error);
        }
    }
Beispiel #28
0
        private IEnumerator TakeScreenshot()
        {
            yield return(new WaitForEndOfFrame());

            var width  = Screen.width;
            var height = Screen.height;
            var tex    = new Texture2D(width, height, TextureFormat.RGB24, false);

            // Read screen contents into the texture
            tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
            tex.Apply();
            byte[] screenshot = tex.EncodeToPNG();

            var wwwForm = new WWWForm();

            wwwForm.AddBinaryData("image", screenshot, "InteractiveConsole.png");
            wwwForm.AddField("message", "herp derp.  I did a thing!  Did I do this right?");
            FB.API("me/photos", HttpMethod.POST, this.HandleResult, wwwForm);
        }
Beispiel #29
0
    IEnumerator UploadPNG()
    {
        yield return(new WaitForEndOfFrame());

        //int width = Screen.width;
        //int height = Screen.height;
        int       width  = 2224;
        int       height = 1668;
        Texture2D tex    = new Texture2D(width, height, TextureFormat.RGB24, false);

        tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
        tex.Apply();

        byte[] bytes = tex.EncodeToPNG();
        UnityEngine.Object.Destroy(tex);

        //System.IO.File.WriteAllBytes(Application.dataPath + "/screenShot.png", bytes);
        WWWForm form = new WWWForm();

        form.AddBinaryData("myimage", bytes, "screenShot.png", "image/png");

        WWW w = new WWW(screenShotURL, form);

        yield return(w);

        if (w.error != null)
        {
            //error :
            if (OnErrorAction != null)
            {
                OnErrorAction(w.error);                 //or OnErrorAction.Invoke (w.error);
            }
        }
        else
        {
            //success
            if (OnCompleteAction != null)
            {
                OnCompleteAction(w.text);                 //or OnCompleteAction.Invoke (w.error);
            }
        }
        w.Dispose();
    }
Beispiel #30
0
        private IEnumerator UploadFileCo(string uploadURL, byte[] dataByteArray, string dataName)
        {
            //Debug.Log("uploadURL " + uploadURL);
            WWWForm postForm = new WWWForm();

            postForm.AddBinaryData("theFile", dataByteArray, dataName, "text/plain");
            UnityWebRequest www = UnityWebRequest.Post(uploadURL, postForm);

            yield return(www.SendWebRequest());

            if (www.isNetworkError || www.isHttpError)
            {
                Debug.Log(www.error);
            }
            else
            {
                Debug.Log("From upload complete!");
            }
        }
 //    public void sendPicture(){
 //        WWW file = new WWW (Application.dataPath + "/Assets/MyScreenshot.png");
 //        yield return localFile;
 //        WWWForm form = new WWWForm ();
 //        form.AddBinaryData();
 //
 //    }
 IEnumerator UploadFileCo(string uploadURL)
 {
     WWW localFile = new WWW("Assets/MyScreenshot.png");
     yield return localFile;
     WWWForm postForm = new WWWForm();
     postForm.AddBinaryData("heatmap", localFile.bytes, "MyScreenshot.png", "image/png");
     WWW upload = new WWW(uploadURL, postForm);
     yield return upload;
     if (upload.error == null)
     {
         Debug.Log(upload.text);
     }
     else
     {
         Debug.Log("Error during upload: " + upload.error);
     }
 }