I post to server raw byte [] of texture but shows 5B in sql database and when this data is downloaded the file is empty. Can you please provide guidance?
I post to server the raw byte[] of a texture like so:
byte [] imgByte0 = uploadedTex.GetRawTextureData();//uploadTex is Texture2D
Debug.Log("Byte Len " + imgByte0.Length);//results in 722160
WWWForm form = new WWWForm();;
form.AddBinaryData("rgbImgBytes", imgByte0, "image/png");
UnityWebRequest www = UnityWebRequest.Post("https:address.php", form);
yield return www.SendWebRequest();
$thisRGBImg=$_FILES['rgbImgBytes'];
$stmt = $conn->prepare("INSERT INTO $imageTable `thisRGBImg` VALUES (?)");
$stmt->execute([$thisRGBImg];
Png image is 300Kb, however it shows as 5B held in sql database BLOB. I further confirm when I download these raw bytes to file (as per https://thoughtbot.com/blog/avoiding-out-of-memory-crashes-on-mobile#streams-to-the-rescue) and resulting file is empty:
using (UnityWebRequest myWebRequest = UnityWebRequest.Post(path, formData2))
{
myWebRequest.downloadHandler = new ToFileDownloadHandler(new byte[64 * 1024], savePathWithFileName);
yield return myWebRequest.SendWebRequest();
}
public ToFileDownloadHandler(byte[] buffer, string filepath) : base(buffer)
{
this.filepath = filepath;
fileStream = new FileStream(filepath, FileMode.Create, FileAccess.Write);
}
protected override bool ReceiveData(byte[] data, int dataLength)
{
if (data == null || data.Length < 1)
{
Debug.Log("ReceiveData - received a null/empty buffer");
return false;
}
received += dataLength;
Debug.Log("Data received " + dataLength + " total received " + received);
//if (!canceled) fileStream.Write(data, 0, dataLength);//replaced for bw below
if (!canceled)
{
var bw = new BinaryWriter(File.Open("path", FileMode.OpenOrCreate));
bw.Write(data);
bw.Flush();
bw.Close();
}
return true;
}