Android Question Kindly check my code

microbox

Active Member
Licensed User
Longtime User
Hello everyone...I have simple app that can query, insert and delete records using MySql as back end database. But I also want to try to load an image and save to database. I copied the following codes for testing..I don't have any error but when calling the function to save the image file no file is saved.
Kindly check the code...
B4X:
 Dim InputStream1 As InputStream
    Try
    InputStream1 = File.OpenInput("/storage/sdcard0/map", "1.jpg")
    ToastMessageShow("File exist!",False)
    Catch
    ToastMessageShow("OOPs no file exist!",False)
    End Try
    Dim OutputStream1 As OutputStream
    OutputStream1.InitializeToBytesArray(1000)
    File.Copy2(InputStream1, OutputStream1)
    Dim Buffer() As Byte 'declares an empty array
    Buffer = OutputStream1.ToBytesArray   
    'write the image to the database
    Try
    ExecuteRemoteQuery("INSERT INTO pictures VALUES('One', Array As Object(Buffer))",MENUS_LIST)
    ToastMessageShow("Saving file done",False)
    Catch
    ToastMessageShow("Not save!",False)
    End Try
I appreciate any help...


Thanks in advance,
microbox
 

microbox

Active Member
Licensed User
Longtime User
This line is wrong:
"INSERT INTO pictures VALUES('One', Array As Object(Buffer))"

It just sends that string. You need to encode the buffer to Base 64 string and then decode it on the server.

A much better and simpler solution is to switch to RDC which supports blobs.
Thanks Erel...I will try RDC and post here my result.
 
Upvote 0
Top