I have a byte array (png image) stored in a row in my SQLite database.
I need to extract the image and send it to a file on my PC server.
I'm using Prefix mode.
I am getting the image out of the SQLite table using
B4X:
Dim Blb() As Byte = RCsr.GetBlob("Data")
I believe the blb array will NOT be in LittleEndian. I have tried to copy the array using ByteConverter as follows:
B4X:
Dim Blb() As Byte = RCsr.GetBlob("Data")
Dim Blob(Blb.Length) As Byte
Dim bc As ByteConverter
bc.LittleEndian = True 'convert to little endian
bc.ArrayCopy(Blb, 0, Blob, 0, Blb.Length)
Astreams.Write(Blob) 'Send the byte array containing the image
and subsequently I would like to send the BLOB array to my server as a memory stream, if possible.
Apparently, the prefix mode "size" bytes are still not in the proper order, thus the data transmission size is distorted.
Is there a way to use Prefix mode to send an "in memory" byte array stream to the PC server without having to save it to a file and send from there?
Thanks,
Rusty
Ok, after some experimentation and me gaining better understanding... I have found the following works:
B4X:
SUB SendByteArray(ByteArray() as Byte)
Dim Blob(ByteArray.Length) As Byte
Dim bc As ByteConverter
bc.LittleEndian = True 'convert to little endian
bc.ArrayCopy(ByteArray, 0, Blob, 0, FileSize)
Dim In As InputStream 'create an input stream from which to read
In.InitializeFromBytesArray(Blob, 0, Blob.Length)
Astreams.Writestream(In, Blob.Length) 'Send the byte array containing the image
...
You can create an inputstream from a byte array and use WriteStream to send it.
I write this in case others make the same mistake as I have.
Regards,
Rusty