Android Question Insert image in remote DB...

Spectre

Active Member
Licensed User
Longtime User
Hi!

I wanted to ask if you can have some examples to insert an image into a blob SqlLite DB on an online server. Using a PHP script that resident on the site and for now I can enter the data correctly, but I do not know how to deal with a blob field ...

Spectre...

B4X:
Sub ExecuteRemoteQuery1(JobName As String, Valore As Int, campo1 As String, campo2 As String, campo3 As String, campo4 As String, campo5 As String, campo6 As String, campo7 As String, campo8 As String, campo9 As String, campo10 As String, campo11 As String, campo12 As String, campo13 As String, campo14 As String, campo15 As String, campo16 As String)
 
    'query di inserimento dati nel database on line
    ' 
    Dim job As HttpJob
    Dim MySQL1 As String
 
    job.Initialize(JobName, Me)         
    MySQL1="INSERT INTO PianteMappate VALUES  (" & Valore & ",'" & campo1 & "','" & campo2 & "','" & campo3 & "','" & campo4 & "','" & campo5  & "','"
    MySQL1=MySQL1 & campo6  & "','" &  campo7  & "','" & campo8  & "','" & campo9  & "','" & campo10  & "','"
    MySQL1=MySQL1 & campo11  & "','" &  campo12  & "','" & campo13  & "','" & campo14  & "','" & campo15 & "','" & campo16   & "')"
    job.PostString("http://xxxxxx.org/DatMappati.php", MySQL1)
End Sub
 
Last edited:

KMatle

Expert
Licensed User
Longtime User
Hi spectre,

it is always good to use the forums's search function ;-) Otherwise it is most likely that you don't get an answer.

https://www.b4x.com/android/forum/threads/read-and-write-blob-text-field-sqlite.55769/#post-351274

This one includes also an image example. It's all about writing the content into a Base64 string (from Bytes) to make it platform compatible.
After that we're talking about a "long string". I don't use SqLite but for sure there are many of examples how to store it (as a BLOB).
 
Upvote 0

Spectre

Active Member
Licensed User
Longtime User
Hi spectre,

it is always good to use the forums's search function ;-) Otherwise it is most likely that you don't get an answer.

https://www.b4x.com/android/forum/threads/read-and-write-blob-text-field-sqlite.55769/#post-351274

This one includes also an image example. It's all about writing the content into a Base64 string (from Bytes) to make it platform compatible.
After that we're talking about a "long string". I don't use SqLite but for sure there are many of examples how to store it (as a BLOB).


Hi!

I had already seen this post ! I have to put the picture in the local db , my question was how do I pass the request to insert it into a db residing on my website wb where he made the php script that takes care of sql requests ...
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Easy...

1. Read the image's content into a byte array (Here I use Random Access File)

B4X:
Dim upl As RandomAccessFile
    Dim l As Int
   
    upl.Initialize(File.DirApp &"\Export\" & ReceiverUsernummer,filename&".ENC", False)
   
    l = upl.Size
    Dim FileBuffer(l) As Byte, fileString As String
    upl.ReadBytes(FileBuffer,0,l,upl.CurrentPosition)
    upl.Close

2. Convert the bytes into a Base64 string:

B4X:
Dim su As StringUtils
fileString=su.EncodeBase64(FileBuffer)

3. Put the Base64 string with the image and the filename into a map

B4X:
JsonZeileMap.put("UploadFileName", filename)
JsonZeileMap.put("FileContent", fileString)

4. Use HttpUtils (PostString) to send it to your php script

5. In the php use

B4X:
$json = file_get_contents("php://input");

6. Put $json to an array and get UploadFileName & FileContent back to store it in your database
 
Upvote 0
Top