Hi Some confusion over what steps are necessary to upload binary data(image) and then handle a JSON response. My understanding is that the uploading (and serialization) can be handled by the WWW class. ie the following in a coroutine Code (CSharp): int width = Screen.width; int height = Screen.height; Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false); tex.ReadPixels(new Rect(0, 0, width, height), 0, 0); tex.Apply(); //This basically takes a screenshot byte[] bytes = tex.EncodeToPNG(); Destroy(tex); // Create a Web Form, this will be our POST data var form = new WWWForm(); form.AddField("somefield", "somedata"); form.AddBinaryData("file", bytes, "screenshot.png", "image/png"); //POST the screenshot WWW w = new WWW(uploadUrl, form); How then would I handle the JSON response? Any feedback appreciated!
There's three things here: 1. getting the texture data (you're just making a blank Texture, I assume for testing purposes) ready to go and into an array of bytes 2. encoding and sending binary data to your server, however the server accepts it 3. parsing the server response, however the server sends it. You would need to know this data shape. If the server has a swagger page then you can do all kinds of easy testing to construct your sending code. If not I would recommend starting from some tutorials for uploading binary data, assuming you can find one that matches the type of server you have or are contemplating.