UnityEngine.WWWForm.AddBinaryData C# (CSharp) Method

AddBinaryData() public method

Add binary data to the form.

public AddBinaryData ( string fieldName, byte contents, [ fileName, [ mimeType ) : void
fieldName string
contents byte
fileName [
mimeType [
return void
        public void AddBinaryData(string fieldName, byte[] contents, [DefaultValue("null")] string fileName, [DefaultValue("null")] string mimeType)
        {
            this.containsFiles = true;
            bool flag = ((((contents.Length > 8) && (contents[0] == 0x89)) && ((contents[1] == 80) && (contents[2] == 0x4e))) && (((contents[3] == 0x47) && (contents[4] == 13)) && ((contents[5] == 10) && (contents[6] == 0x1a)))) && (contents[7] == 10);
            if (fileName == null)
            {
                fileName = fieldName + (!flag ? ".dat" : ".png");
            }
            if (mimeType == null)
            {
                if (flag)
                {
                    mimeType = "image/png";
                }
                else
                {
                    mimeType = "application/octet-stream";
                }
            }
            this.fieldNames.Add(fieldName);
            this.fileNames.Add(fileName);
            this.formData.Add(contents);
            this.types.Add(mimeType);
        }

Same methods

WWWForm::AddBinaryData ( string fieldName, byte contents ) : void
WWWForm::AddBinaryData ( string fieldName, byte contents, string fileName ) : void

Usage Example

コード例 #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");
        }
    }
All Usage Examples Of UnityEngine.WWWForm::AddBinaryData