Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Android Base64

Discussion in 'Editor & General Support' started by FeloiLLC, May 11, 2021.

  1. FeloiLLC

    FeloiLLC

    Joined:
    May 11, 2021
    Posts:
    1
    When I do this in editor, it works perfect. When I do this code in android or apple, the base64 string is cut to around 800 characters and doesn't work. Any Suggestions?
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using System;
    5. using UnityEngine.Networking;
    6.  
    7. public class supersimple : MonoBehaviour
    8. {
    9.     public Texture2D tex;
    10.  
    11.     public void convertTex()
    12.     {
    13.  
    14.         byte[] tmp = tex.GetRawTextureData();
    15.         Texture2D tmpTexture = new Texture2D(tex.width, tex.height, tex.format, false);
    16.         tmpTexture.LoadRawTextureData(tmp);
    17.         tmpTexture.Apply();
    18.         string stringData = Convert.ToBase64String(tmpTexture.EncodeToPNG());
    19.  
    20.  
    21.         StartCoroutine(base64(stringData));
    22.  
    23.     }
    24.  
    25.  
    26.     public IEnumerator base64(string data)
    27.  
    28.     {
    29.         WWWForm form = new WWWForm();
    30.         form.AddField("64Data", data);
    31.         UnityWebRequest uwr = UnityWebRequest.Post("https://www.feloi.com/test.php", form);
    32.         yield return uwr.SendWebRequest();
    33.         if (uwr.isNetworkError)
    34.         {
    35.             Debug.Log("Error While Sending: " + uwr.error);
    36.         }
    37.         else
    38.         {
    39.             Debug.Log("Received: " + uwr.downloadHandler.text);
    40.         }
    41.     }
    42. }
     
    Last edited: May 11, 2021