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

Base64 string

Discussion in 'Scripting' started by Marikosama, Oct 2, 2015.

  1. Marikosama

    Marikosama

    Joined:
    Jun 26, 2015
    Posts:
    13
    I convert an image and store it into the database then i retrieve it to convert back into byte it tells me invalid length. Why is this happening? Anyone has any solution?
     
  2. Roland1234

    Roland1234

    Joined:
    Nov 21, 2012
    Posts:
    190
    Could you post the relevant code doing your image conversions to/from your database format? From your title I'm assuming you're converting an image byte[] to and from a base64 string. With a Texture2D you should be able to use GetRawTextureData or EncodeToJPG/PNG methods and LoadRawTextureData or LoadImage methods to convert to/from a byte[]. Then you should be able to use System.Convert.To/FromBase64String to convert between a byte[] and a base64 string.

    If none of that works, the only thing thta occurs to me is that maybe your base64 string is getting padded or something either somewhere in the conversions or as it's inserted and retrieved from you DB. Can you provide more details?