Steps to send and recv image

Currently, my app looks like this:

User can upload a small icon image (or use the default one) that is associated with an object. In Unity this is displayed to the user as an Image.

When they go to submit the form that will send their object details to be saved in the DB, these are the steps I’m doing to send and recv the image:

Send:

byte[] imgBytes = uiImg.sprite.texture.EncodeToPNG();
string imgStr = Convert.ToBase64String(imgBytes);

I then POST this via HTTP.

When the user goes back to the page and wants to see their current objects with the icons they uploaded (or the default one if they didn’t upload a custom icon), I talk to my server and get the data in JSON format. I then try to get the image and display it back to the user via:

Recv:

byte[] tmpBytes = Convert.FromBase64String(iconImg);
Texture2D imgTexture = new Texture2D(500, 500);
imgTexture.LoadImage(tmpBytes);
uiImg.sprite = Sprite.Create(imgTexture, new Rect(0, 0, imgTexture.width, imgTexture.height), new Vector2(1.0f, 1.0f));

But after this loads, the image has no sprite and is empty. It is clearly changing the default source image to empty in the editor.

Some progress:

After changing the recv code to this, the Image now displays a question mark instead of being empty:

byte[] tmpBytes = Convert.FromBase64String(iconImg);
Texture2D imgTexture = new Texture2D(500, 500);
imgTexture.LoadImage(tmpBytes);
imgTexture.Apply();
uiImg.sprite = Sprite.Create(imgTexture, new Rect(0, 0, imgTexture.width, imgTexture.height), new Vector2(1.0f, 1.0f));

9037042--1247782--Screenshot 2023-05-25 at 8.11.20 AM.png

Networking, UnityWebRequest, WWW, Postman, curl, WebAPI, etc:

And setting up a proxy can be very helpful too, in order to compare traffic: