AddBinaryData() private method

private AddBinaryData ( string fieldName, byte contents ) : void
fieldName string
contents byte
return void
コード例 #1
0
ファイル: TestScript.cs プロジェクト: 9bits/evaluator
    IEnumerator UploadJPG()
    {
        // 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("fileUpload", bytes, @"C:\images\img_file.jpg", "image/jpg");

        // Upload to a cgi script
        WWW w = new WWW(url, form);
        yield return w;
        if (!string.IsNullOrEmpty(w.error)) {
            print(w.error);
        }
        else {
            print("Finished Uploading Screenshot");
        }
    }
コード例 #2
0
	private IEnumerator FBLoginProcess()
	{
		Debug.Log("Prompt FB login");
		yield return StartCoroutine(FacebookWrapper.Login());

		if (!FacebookWrapper.IsLoggedIn)
		{
			Debug.LogError("Login failed/canceled!");
		}
		else
		{
			Debug.Log("FB connected! Testing permissions.");
			FB.API("/me/permissions", HttpMethod.GET, delegate (IGraphResult response) {
				if (!string.IsNullOrEmpty(response.Error))
				{
					Debug.LogError("Error retrieving permissions.");
				}
				else
				{
					Debug.Log ("Retrieved permissions: " + response.RawResult.ToString());
				}
			});



			WWWForm wwwForm = new WWWForm();
			wwwForm.AddField("message", "I just discovered the activity \"Monday Morning Walk\". Discover more activities at: https://choosehealthier.org/node/10374");
			wwwForm.AddBinaryData("image", tex.EncodeToPNG());
			//wwwForm.AddField("access_token", FB.AccessToken);

			//FB.API("/me/feed", Facebook.HttpMethod.POST, OnPostSuccess, wwwForm);
			FB.API("/me/photos", HttpMethod.POST, OnPostSuccess, wwwForm);
		}
	}
コード例 #3
0
ファイル: TakeAScreenshot.cs プロジェクト: Gounemond/GGJ2016
    public IEnumerator ScreenshotHappy(int playerCount)
    {
        //Miro dove stanno i giocatori (trucco: con 0 fa tutto lo schermo
        Vector2 imageFrom = playerCount <=1 ? new Vector2(0, 0) : new Vector2(Screen.width / 2, Screen.height / 2);
        Vector2 imageTo = playerCount == 1 ? new Vector2(Screen.width / 2, Screen.height / 2) : new Vector2(Screen.width, Screen.height);
        
        byte[] temp = GetScreenshot(CaptureMethod.RenderToTex_Synch, imageFrom, imageTo).EncodeToJPG();
        byte[] report = new byte[temp.Length];
        for (int i = 0; i < report.Length; i++)
        {
            report[i] = (byte)temp[i];
        } // for
        // create a form to send the data to the sever
        WWWForm form = new WWWForm();
        // add the necessary data to the form
        form.AddBinaryData("upload_file", report, "spinder.jpg", "image/jpeg"); ;
        // send the data via web
        WWW www2 = new WWW("http://risingpixel.azurewebsites.net/other/apps/spinder/upload.php", form);
        // wait for the post completition
        while (!www2.isDone)
        {
            Debug.Log("I'm waiting... " + www2.uploadProgress);
            yield return new WaitForEndOfFrame();
        } // while
        // print the server answer on the debug log
        Debug.Log(www2.text);
        // destroy the www
        www2.Dispose();

        yield return null;
        taking = false;

        yield return new WaitForSeconds(.2f);
    }
コード例 #4
0
ファイル: NetLogDevice.cs プロジェクト: zhutaorun/unitygame
 // 如果想通过HTTP传递二进制流的话 可以使用 下面的方法。
 public void sendBinaryData(string url, string str)
 {
     WWWForm wwwForm = new WWWForm();
     byte[] byteStream = System.Text.Encoding.Default.GetBytes(str);
     wwwForm.AddBinaryData("post", byteStream);
     WWW www = new WWW(url, wwwForm);
 }
コード例 #5
0
    IEnumerator ApplyShare()
    {
        shareToFBPanel_anim.SetBool ("show", false);
        string message = transform.parent.Find ("Message").Find ("Text").GetComponent<Text> ().text;

        yield return new WaitForSeconds(.5f);
        #if UNITY_EDITOR
        Debug.Log ("Capture screenshot and share.");
        Debug.Log ("Message: "+message);
        GameObject.Find ("ResultPanel").SendMessage("ShareToFB", false);
        #elif UNITY_ANDROID
        var snap = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
        snap.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
        snap.Apply();
        var screenshot = snap.EncodeToPNG();

        var wwwForm = new WWWForm();
        wwwForm.AddBinaryData("image", screenshot, "screenshot.png");
        wwwForm.AddField("message", message);

        FB.API(
            "/me/photos",
            Facebook.HttpMethod.POST,
            delegate (FBResult r) {
                GameObject.Find("ResultPanel").SendMessage("ShareToFB", false);
            },
            wwwForm
        );
        #endif
    }
コード例 #6
0
ファイル: DropboxTest.cs プロジェクト: Dstaal/MasterProject
    public void UploadFileToDropbox(string path)
    {
        var text = File.ReadAllText(path);
        if (string.IsNullOrEmpty(text))
        {
            throw new ArgumentNullException("path", path + " is not a valid path or no file exists at the path");
        }

        var bytes = Encoding.UTF8.GetBytes(text);
        if (bytes.Length == 0)
        {
            throw new ArgumentNullException("bytes", "File at " + path + " did not give a valid bytes length after encoding");
        }

        var data = @"
        {
            'path': '" + path + @"',
            'mode': 'add',
            'autorename': true,
            'mute': false
        }".Trim();

        var headers = new Dictionary<string, string>(3);
        headers.Add("Authorization", "Bearer ie9epjU43NcAAAAAAAATeutD8nT5PHuUU3hL7NM2QDTzZNKUpIzdUKLfF2TDErr5");
        headers.Add("Content-Type", "application/octet-stream");
        headers.Add("Dropbox-API-Arg", data);

        var form = new WWWForm();
        form.AddBinaryData("data-binary", bytes);

        var www = new WWW("https://content.dropboxapi.com/2/files/upload", form.data, headers);
        Debug.Log(this.ToString() + " making a POST to :" + www.url);

        StartCoroutine(UploadFileToDropboxInternal(www));
    }
コード例 #7
0
 public void GetAgeGroup(string filePath)
 {
     string url = "https://api.idolondemand.com/1/api/sync/detectfaces/v1";
     WWWForm form = new WWWForm ();
     form.AddField ("apikey", "a3d67cd8-4b59-4783-84d8-dc45fedea5f4");
     byte[] binaryData = File.ReadAllBytes (filePath);
     form.AddBinaryData ("file", binaryData, Path.GetFileName (filePath), "text/plain");
     form.AddField("additional", "true");
     WWW www = new WWW(url, form);
     StartCoroutine(WaitForRequest(www));
 }
コード例 #8
0
 public void ShareImage(Texture2D image, string imageName, string message)
 {
     byte[] imageContent = image.EncodeToPNG();
     WWWForm www = new WWWForm ();
     www.AddBinaryData ("image", imageContent, imageName);
     www.AddField ("message", message);
     if (FB.IsLoggedIn)
     {
         FB.API ("me/photos", HttpMethod.POST, CallbackShareImage, www);
     }
 }
コード例 #9
0
    protected void WWWFormRequest()
    {
        WWWForm form = new WWWForm ();
                form.AddBinaryData ("tab.text", new byte[]{0,1,2});

                if (form != null && form.headers.Count > 0) {
                        var headers = new Hashtable (); // add content-type
                        IDictionaryEnumerator formHeadersIterator = form.headers.GetEnumerator ();
                        while (formHeadersIterator.MoveNext())
                                headers.Add ((String)formHeadersIterator.Key, formHeadersIterator.Value);
                }
    }
コード例 #10
0
ファイル: wwHttpUploadFile.cs プロジェクト: wikeryong/uTools
 public override WWW CreateWWW()
 {
     WWWForm form = new WWWForm();
     if (string.IsNullOrEmpty(httpInfo.uploadFile))
     {
         byte[] b = ReadFile(httpInfo.uploadFile);
         FileInfo f = new FileInfo(httpInfo.uploadFile);
         form.AddBinaryData(f.Name, b, f.Name);
     }
     WWW www = wwHttp.WWWPost(httpInfo.url, form);
     httpInfo.www = www;
     return www;
 }
コード例 #11
0
 static public int AddBinaryData(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 3)
         {
             UnityEngine.WWWForm self = (UnityEngine.WWWForm)checkSelf(l);
             System.String       a1;
             checkType(l, 2, out a1);
             System.Byte[] a2;
             checkArray(l, 3, out a2);
             self.AddBinaryData(a1, a2);
             pushValue(l, true);
             return(1);
         }
         else if (argc == 4)
         {
             UnityEngine.WWWForm self = (UnityEngine.WWWForm)checkSelf(l);
             System.String       a1;
             checkType(l, 2, out a1);
             System.Byte[] a2;
             checkArray(l, 3, out a2);
             System.String a3;
             checkType(l, 4, out a3);
             self.AddBinaryData(a1, a2, a3);
             pushValue(l, true);
             return(1);
         }
         else if (argc == 5)
         {
             UnityEngine.WWWForm self = (UnityEngine.WWWForm)checkSelf(l);
             System.String       a1;
             checkType(l, 2, out a1);
             System.Byte[] a2;
             checkArray(l, 3, out a2);
             System.String a3;
             checkType(l, 4, out a3);
             System.String a4;
             checkType(l, 5, out a4);
             self.AddBinaryData(a1, a2, a3, a4);
             pushValue(l, true);
             return(1);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
    //Making the request
    public void MakeFaceRequest(string PhotoLocation)
    {
        Debug.Log ("Logré llegar desde el storyTeller");
        //Filling the form
        WWWForm FaceForm = new WWWForm ();
        FaceForm.AddField ("client_id",client_Id);
        FaceForm.AddField ("app_key", app_Key);
        FaceForm.AddField ("attribute", "age, gender, expressions");
        FaceForm.AddBinaryData ("img", System.IO.File.ReadAllBytes(PhotoLocation), "snapshot0.jpg","multipart/Form-data");

        //Preparing the answer
        WWW URLConnection = new WWW (URL,FaceForm);
        StartCoroutine (WaitForRequest (URLConnection, FaceForm));
    }
コード例 #13
0
    private static IEnumerator SendData(byte[] data)
    {
        // Create POST form for data
        WWWForm form = new WWWForm();

        form.AddBinaryData("data", data);

        // Upload the form to the web server
        WWW www = new WWW("http://creepingwillow.com/scores.php?submit", form);

        yield return www;

        if (www.text == "Success") Debug.Log("Successfully uploaded score to the server.");
        else Debug.Log("Error uploading score to the server: " + www.text);
    }
コード例 #14
0
ファイル: sendTest.cs プロジェクト: 232fumiya/UnityStudy
 private IEnumerator sendDataTest()
 {
     string URL = "データを飛ばすurl";
     WWWForm form = new WWWForm ();
     //受け取り側はsendDataTest.phpを参照して下さい・
     form.AddField("test",message);
     //受け取り側はSampleSendImage.phpを参照して下さい・
     form.AddBinaryData("image",bytes,"img.png","image/png");
     WWW www = new WWW (URL,form);
     yield return www;
     if (www.error != null)
         Debug.Log (www.error);
     else
         Debug.Log("success!");
 }
コード例 #15
0
 static public int AddBinaryData(IntPtr l)
 {
     try{
         if (matchType(l, 2, typeof(string), typeof(System.Byte[]), typeof(string)))
         {
             UnityEngine.WWWForm self = (UnityEngine.WWWForm)checkSelf(l);
             System.String       a1;
             checkType(l, 2, out a1);
             System.Byte[] a2;
             checkType(l, 3, out a2);
             System.String a3;
             checkType(l, 4, out a3);
             self.AddBinaryData(a1, a2, a3);
             return(0);
         }
         else if (matchType(l, 2, typeof(string), typeof(System.Byte[])))
         {
             UnityEngine.WWWForm self = (UnityEngine.WWWForm)checkSelf(l);
             System.String       a1;
             checkType(l, 2, out a1);
             System.Byte[] a2;
             checkType(l, 3, out a2);
             self.AddBinaryData(a1, a2);
             return(0);
         }
         else if (matchType(l, 2, typeof(string), typeof(System.Byte[]), typeof(string), typeof(string)))
         {
             UnityEngine.WWWForm self = (UnityEngine.WWWForm)checkSelf(l);
             System.String       a1;
             checkType(l, 2, out a1);
             System.Byte[] a2;
             checkType(l, 3, out a2);
             System.String a3;
             checkType(l, 4, out a3);
             System.String a4;
             checkType(l, 5, out a4);
             self.AddBinaryData(a1, a2, a3, a4);
             return(0);
         }
         LuaDLL.luaL_error(l, "No matched override function to call");
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
コード例 #16
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, handleResult, wwwForm);
        }
コード例 #17
0
    IEnumerator Uploader()
    {
        WWWForm form = new WWWForm();
        form.AddField("action", "upload level");
        form.AddField("file", "file");
        form.AddBinaryData("file", LevelIO.GetBytes(level.Level), "test.cowl", "application/octet-stream");

        www = new WWW(uploadUrl,form);
        yield return www;
        if (www.error != null)
        {
            Debug.LogError(www.error);
        }
        else
        {
            UploadComplete();
        }
    }
コード例 #18
0
ファイル: WebManager.cs プロジェクト: hcyxt/www
    //上传PNG图片,通过EncodeToPNG函数将PNG图片变为byte数组
    IEnumerator IRequestPNG()
    {
        byte[] bs = m_uploadImage.EncodeToPNG();

        WWWForm form = new WWWForm();
        form.AddBinaryData("picture", bs, "screenshot", "image/png");

        WWW www = new WWW("http://7ROAD-20140625X.7road.com/test/test.php", form);

        yield return www;

        if (www.error != null)
        {
            m_info = www.error;
            yield return null;
        }
        m_downloadTexture = www.texture;
    }
コード例 #19
0
    private IEnumerator PostData(string url)
    {
        WWWForm form = new WWWForm();
        form.AddBinaryData(FIELD_NAME, SerializeData(),SAVE_FILE_NAME);
        WWW www = new WWW(url,form);
        yield return www;

        if (!string.IsNullOrEmpty(www.error))
        {
            print(www.error);
          
        }
        else
        {
            text.text = string.Format(SAVE_DONE, DateTime.Now);
            www.Dispose();
        }

    }
コード例 #20
0
 public void UploadFile(byte[] localFile, string uploadURL, RequsetSuccess function, RequestErr ErrFunction = null)
 {
     //WWW localFile = new WWW("file:///" + localFileName);
     //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("file", localFile, "photo_" + DateTime.Now.Ticks + ".jpg", "image/png");
     WWW upload = new WWW(uploadURL, postForm);
     StartCoroutine(WaitForRequest(upload, function, ErrFunction));
 }
コード例 #21
0
    static int AddBinaryData(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 3)
            {
                UnityEngine.WWWForm obj = (UnityEngine.WWWForm)ToLua.CheckObject <UnityEngine.WWWForm>(L, 1);
                string arg0             = ToLua.CheckString(L, 2);
                byte[] arg1             = ToLua.CheckByteBuffer(L, 3);
                obj.AddBinaryData(arg0, arg1);
                return(0);
            }
            else if (count == 4)
            {
                UnityEngine.WWWForm obj = (UnityEngine.WWWForm)ToLua.CheckObject <UnityEngine.WWWForm>(L, 1);
                string arg0             = ToLua.CheckString(L, 2);
                byte[] arg1             = ToLua.CheckByteBuffer(L, 3);
                string arg2             = ToLua.CheckString(L, 4);
                obj.AddBinaryData(arg0, arg1, arg2);
                return(0);
            }
            else if (count == 5)
            {
                UnityEngine.WWWForm obj = (UnityEngine.WWWForm)ToLua.CheckObject <UnityEngine.WWWForm>(L, 1);
                string arg0             = ToLua.CheckString(L, 2);
                byte[] arg1             = ToLua.CheckByteBuffer(L, 3);
                string arg2             = ToLua.CheckString(L, 4);
                string arg3             = ToLua.CheckString(L, 5);
                obj.AddBinaryData(arg0, arg1, arg2, arg3);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.WWWForm.AddBinaryData"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
コード例 #22
0
 public IEnumerator CaptureScreenshot(string uploadUrl)
 {
     yield return new WaitForEndOfFrame();
     int width = Screen.width;
     int height = Screen.height;
     Texture2D tx = new Texture2D(width, height, TextureFormat.RGB24, false);
     tx.ReadPixels(new Rect(0, 0, width, height), 0, 0);
     tx.Apply();
     yield return new WaitForEndOfFrame();
     byte[] screenshotBytes = tx.EncodeToPNG();
     Destroy(tx);
     WWWForm form = new WWWForm();
     form.AddBinaryData("file1", screenshotBytes);
     var w = new WWW(uploadUrl, form);
     yield return w;
     print(w.text + w.error);
     ExternalCall("PhotoSave", w.text);
     if (showScreenshotText)
         centerText(Tr("ScreenshotUploadedText"));
 }
コード例 #23
0
 static int QPYX_AddBinaryData_YXQP(IntPtr L_YXQP)
 {
     try
     {
         int QPYX_count_YXQP = LuaDLL.lua_gettop(L_YXQP);
         if (QPYX_count_YXQP == 3)
         {
             UnityEngine.WWWForm QPYX_obj_YXQP = (UnityEngine.WWWForm)ToLua.CheckObject <UnityEngine.WWWForm>(L_YXQP, 1);
             string QPYX_arg0_YXQP             = ToLua.CheckString(L_YXQP, 2);
             byte[] QPYX_arg1_YXQP             = ToLua.CheckByteBuffer(L_YXQP, 3);
             QPYX_obj_YXQP.AddBinaryData(QPYX_arg0_YXQP, QPYX_arg1_YXQP);
             return(0);
         }
         else if (QPYX_count_YXQP == 4)
         {
             UnityEngine.WWWForm QPYX_obj_YXQP = (UnityEngine.WWWForm)ToLua.CheckObject <UnityEngine.WWWForm>(L_YXQP, 1);
             string QPYX_arg0_YXQP             = ToLua.CheckString(L_YXQP, 2);
             byte[] QPYX_arg1_YXQP             = ToLua.CheckByteBuffer(L_YXQP, 3);
             string QPYX_arg2_YXQP             = ToLua.CheckString(L_YXQP, 4);
             QPYX_obj_YXQP.AddBinaryData(QPYX_arg0_YXQP, QPYX_arg1_YXQP, QPYX_arg2_YXQP);
             return(0);
         }
         else if (QPYX_count_YXQP == 5)
         {
             UnityEngine.WWWForm QPYX_obj_YXQP = (UnityEngine.WWWForm)ToLua.CheckObject <UnityEngine.WWWForm>(L_YXQP, 1);
             string QPYX_arg0_YXQP             = ToLua.CheckString(L_YXQP, 2);
             byte[] QPYX_arg1_YXQP             = ToLua.CheckByteBuffer(L_YXQP, 3);
             string QPYX_arg2_YXQP             = ToLua.CheckString(L_YXQP, 4);
             string QPYX_arg3_YXQP             = ToLua.CheckString(L_YXQP, 5);
             QPYX_obj_YXQP.AddBinaryData(QPYX_arg0_YXQP, QPYX_arg1_YXQP, QPYX_arg2_YXQP, QPYX_arg3_YXQP);
             return(0);
         }
         else
         {
             return(LuaDLL.luaL_throw(L_YXQP, "invalid arguments to method: UnityEngine.WWWForm.AddBinaryData"));
         }
     }
     catch (Exception e_YXQP)                {
         return(LuaDLL.toluaL_exception(L_YXQP, e_YXQP));
     }
 }
コード例 #24
0
        public override void CopyFrom(HTTPFormBase fields)
        {
            this.Fields = fields.Fields;
            this.IsChanged = true;

            if (Form == null)
            {
                Form = new WWWForm();

                if (Fields != null)
                    for (int i = 0; i < Fields.Count; ++i)
                    {
                        var field = Fields[i];

                        if (string.IsNullOrEmpty(field.Text) && field.Binary != null)
                            Form.AddBinaryData(field.Name, field.Binary, field.FileName, field.MimeType);
                        else
                            Form.AddField(field.Name, field.Text, field.Encoding);
                    }
            }
        }
コード例 #25
0
    IEnumerator UploadPNG()
    {
        // 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
        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();
        // Encode texture into PNG
        byte[] bytes = tex.EncodeToPNG();
        Destroy(tex);
        string filename = "";
        #if UNITY_STANDALONE_WIN
        filename = ScreenShotName(shotName);
        System.IO.File.WriteAllBytes(filename, bytes);
        Debug.Log(string.Format("Took screenshot to: {0}", filename));
        #endif
        #if UNITY_WEBGL
        filename = ScreenShotName(shotName, false) + ".png";
        // Create a Web Form
        WWWForm form = new WWWForm();
        form.AddField("action", "image upload");
        form.AddField("frameCount", Time.frameCount.ToString());
        form.AddBinaryData("fileUpload", bytes, filename, "image/png");
        // Upload to a cgi script
        WWW w = new WWW("http://www.yourdomainname.com/ImageUpload.php", form); // Change to wherever we put the .php file :)
        yield return w;
        if (!string.IsNullOrEmpty(w.error)) {
            print(w.error);
        } else {
            print("Finished Uploading Screenshot");
        }
        #endif
        takeScreenshot = false;
    }
コード例 #26
0
ファイル: WebCam.cs プロジェクト: TeamAlek/Alek
    private IEnumerator accessToServer(byte[] send_bytes)
    {
        var form = new WWWForm();
        form.AddBinaryData("fileUpload", send_bytes, "send.png", "image/png");
        var www = new WWW(URL, form);

        //受信
        yield return www; //受信待機
        if (www.error == null)
        {
            if (www.text != "null")
            {
                print("string : " + www.text);
                CameraFade.StartAlphaFade(Color.white, false, 1f, 0f, () => { Application.LoadLevel("SummonResultScene"); });
                result_txt = www.text;
            }
            else
            {
                print("QRcode not found");
            }
        }
    }
コード例 #27
0
ファイル: IconManager.cs プロジェクト: vmoraesinfo/bestDriver
    IEnumerator UploadPNG()
    {
        // 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.EncodeToPNG();

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

        // Create a Web Form
        WWWForm form = new WWWForm();
        form.AddField("frameCount", Time.frameCount.ToString());
        form.AddBinaryData("fileUpload", bytes);

        // Upload to a cgi script
        WWW w = new WWW("http://localhost/cgi-bin/env.cgi?post", form);
        yield return w;

        if (w.error != null)
        {
            Debug.Log(w.error);
        }
        else {
            Debug.Log("Finished Uploading Screenshot");
        }
    }
コード例 #28
0
ファイル: HttpAPI.cs プロジェクト: npnf-seta/Fox-Poker
        static IEnumerator UploadFile(byte[] avatar, DelegateAPICallback callback)
        {
            WWWForm postForm = new WWWForm();
            postForm.AddField("accessToken", API.Client.APILogin.AccessToken);
            postForm.AddBinaryData("avatar", avatar);
            WWW upload = new WWW(string.Format("{0}/static/api/uploadAvatar", AppConfig.HttpUrl), postForm);
            yield return upload;

            bool status = string.IsNullOrEmpty(upload.error);
            string message = string.IsNullOrEmpty(upload.error) ? upload.text : upload.error;
            
            if(status)
            {
                Dictionary<string, object> dict = Puppet.Utils.JsonUtil.Deserialize(message);
                if (dict != null && dict.ContainsKey("code"))
                    status = int.Parse(dict["code"].ToString()) == 0;

                if (dict != null && dict.ContainsKey("message"))
                    message = dict["message"].ToString();
            }

            if (callback != null)
                callback(status, message);
        }
コード例 #29
0
			/// <summary>
			/// See docs in <see cref="SoomlaProfile.UploadImage"/>
			/// </summary>
			/// <param name="tex2D">Texture2D for image.</param>
			/// <param name="fileName">Name of image file.</param>
		/// <param name="message">Message to post with the image.</param>
		/// <param name="success">Callback function that is called if the image upload was successful.</param>
		/// <param name="fail">Callback function that is called if the image upload failed.</param>
		/// <param name="cancel">Callback function that is called if the image upload was cancelled.</param>
		public override void UploadImage(byte[] texBytes, string fileName, string message, SocialActionSuccess success, SocialActionFailed fail, SocialActionCancel cancel) {
			
			checkPublishPermission( ()=> {
				var wwwForm = new WWWForm();
				wwwForm.AddBinaryData("image", texBytes, fileName);
				wwwForm.AddField("message", message);
				
				FB.API("/me/photos", HttpMethod.POST, 
				       (IGraphResult result) => {
					
					if (result.Error != null) {
						SoomlaUtils.LogDebug(TAG, "UploadImageCallback[result.Error]: "+result.Error);
						fail(result.Error);
					}
					else {
						SoomlaUtils.LogDebug(TAG, "UploadImageCallback[result.Text]: "+result.RawResult);
						SoomlaUtils.LogDebug(TAG, "UploadImageCallback[result.Texture]: "+result.Texture);
						var responseObject = Json.Deserialize(result.RawResult) as Dictionary<string, object>;
						object obj = 0;
                        if (responseObject.TryGetValue("cancelled", out obj)) {
                            cancel();
                        }
                        else /*if (responseObject.TryGetValue ("id", out obj))*/ {
                            success();
                        }
                    }
                    
                }, wwwForm);
			}, (string errorMessage)=>{
				fail(message);
            });
        }
コード例 #30
0
	//send data inet
	public void sendData(string[] vars, string[] values, string action_, byte[] uploadImage = null){
		
		WWWForm form = new WWWForm();
		form.AddField("appHash", appHash);
		form.AddField("action", action_);
		
		int index=0;
		sendDataDebug = "preparando variables";

		foreach (string vars_ in vars) {
			if(vars_ != "fileUpload"){
				try{
					form.AddField(vars_, values[index]);
				}catch(Exception e){
					sendDataDebug = "error en variable: "+index;
				}
			}else{
				form.AddBinaryData("fileUpload", uploadImage);
			}
			index++;
		}

		sendDataDebug = "iniciando WWW";
		
		WWW www = new WWW(responseURL, form);
		StartCoroutine(WaitForRequest(www, action_));
		//Debug.Log(www.text);
		
	}
コード例 #31
0
ファイル: CapturePanorama.cs プロジェクト: EliCDavis/ped-sim
        // Based on http://docs.unity3d.com/ScriptReference/WWWForm.html and
        // http://answers.unity3d.com/questions/48686/uploading-photo-and-video-on-a-web-server.html
        IEnumerator UploadImage(byte[] imageFileBytes, string filename, string mimeType, bool async)
        {
            float startTime = Time.realtimeSinceStartup;

            WWWForm form = new WWWForm();

            form.AddField("key", apiKey);
            form.AddField("action", "upload");
            form.AddBinaryData("source", imageFileBytes, filename, mimeType);

            WWW w = new WWW(apiUrl + "upload", form);
            yield return w;
            if (!string.IsNullOrEmpty(w.error))
            {
                Debug.LogError("Panorama upload failed: " + w.error, this);
                if (failSound != null && Camera.main != null)
                    audioSource.PlayOneShot(failSound);
            }
            else
            {
                Log("Time to upload panorama screenshot: " + (Time.realtimeSinceStartup - startTime) + " sec");
                if (!captureEveryFrame && doneSound != null && Camera.main != null)
                {
                    audioSource.PlayOneShot(doneSound);
                }
            }
            Capturing = false;
        }
コード例 #32
0
ファイル: GUIFB.cs プロジェクト: MizzKii/PuruDash2D
	/*#region FB.Feed() example
	
	public string FeedToId = "";
	public string FeedLink = "";
	public string FeedLinkName = "";
	public string FeedLinkCaption = "";
	public string FeedLinkDescription = "";
	public string FeedPicture = "";
	public string FeedMediaSource = "";
	public string FeedActionName = "";
	public string FeedActionLink = "";
	public string FeedReference = "";
	public bool IncludeFeedProperties = false;
	private Dictionary<string, string[]> FeedProperties = new Dictionary<string, string[]>();
	
	public void CallFBFeed()
	{
		Dictionary<string, string[]> feedProperties = null;
		if (IncludeFeedProperties)
		{
			feedProperties = FeedProperties;
		}
		FB.Feed(
			toId: FeedToId,
			link: FeedLink,
			linkName: FeedLinkName,
			linkCaption: FeedLinkCaption,
			linkDescription: FeedLinkDescription,
			picture: FeedPicture,
			mediaSource: FeedMediaSource,
			actionName: FeedActionName,
			actionLink: FeedActionLink,
			reference: FeedReference,
			properties: feedProperties,
			callback: Callback
			);
	}
	
	#endregion*/

	public 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", "Hi! Friends, Can you beat me?");
		
		FB.API("me/photos", Facebook.HttpMethod.POST, Callback, wwwForm);
		gameObject.GetComponent<GUIEnd>().share = true;
	}
コード例 #33
0
 static public int AddBinaryData(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 3)
         {
             UnityEngine.WWWForm self = (UnityEngine.WWWForm)checkSelf(l);
             System.String       a1;
             checkType(l, 2, out a1);
             System.Byte[] a2;
             checkArray(l, 3, out a2);
             self.AddBinaryData(a1, a2);
             pushValue(l, true);
             return(1);
         }
         else if (argc == 4)
         {
             UnityEngine.WWWForm self = (UnityEngine.WWWForm)checkSelf(l);
             System.String       a1;
             checkType(l, 2, out a1);
             System.Byte[] a2;
             checkArray(l, 3, out a2);
             System.String a3;
             checkType(l, 4, out a3);
             self.AddBinaryData(a1, a2, a3);
             pushValue(l, true);
             return(1);
         }
         else if (argc == 5)
         {
             UnityEngine.WWWForm self = (UnityEngine.WWWForm)checkSelf(l);
             System.String       a1;
             checkType(l, 2, out a1);
             System.Byte[] a2;
             checkArray(l, 3, out a2);
             System.String a3;
             checkType(l, 4, out a3);
             System.String a4;
             checkType(l, 5, out a4);
             self.AddBinaryData(a1, a2, a3, a4);
             pushValue(l, true);
             return(1);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function AddBinaryData to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
コード例 #34
0
        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--;
        }
コード例 #35
0
	IEnumerator UploadLevel(byte[] data, string uploadURL, string filename)
	{
		WWWForm form = new WWWForm();

		form.AddField("action", "level upload");
		form.AddField("file", "file");
		form.AddBinaryData("file", data, filename, "images/jpg");
		Debug.Log("url " + uploadURL);

		WWW w = new WWW(uploadURL, form);
		yield return w;

		if ( w.error != null )
		{
			print("error");
			print(w.error);
		}
		else
		{
			if ( w.uploadProgress == 1 && w.isDone )
			{
				yield return new WaitForSeconds(5);
			}
		}
	}