Android Question Getting filename from Content Chooser

Makumbi

Well-Known Member
Licensed User
Please help i have used the content Chooser to get to the gallery now my problem is getting that photo then upload it to my SQLite Database please help

B4X:
    Dim chooser As ContentChooser
    If chooser.IsInitialized = False Then
        chooser.Initialize("chooser")
    End If
    chooser.show("image/*", "Choose image")
Blelow is my code for the Registered Users
B4X:
cursor1 = SQL1.ExecQuery("SELECT ID FROM Register")
If cursor1.RowCount > 0 Then
    For i = 0 To cursor1.RowCount - 1
        cursor1.Position = i
        Dim NewID As Int
        NewID = cursor1.GetInt("ID")
    Next
End If
NewID = NewID +1 '
SQL1.ExecNonQuery("INSERT INTO Register VALUES('" & CCode.Text & "','" & Phone.Text & "','" & Emails.Text & "','" & NewID & "')")
'SQL1.ExecNonQuery("INSERT INTO Register VALUES('" & CCode.Text & "','" & Phone.Text & "','" & Emails.Text & "')")
    Msgbox("Registration Completed Successfully","SMIS")
    'End If
 

ronell

Well-Known Member
Licensed User
Longtime User
B4X:
Dim chooser As ContentChooser
    If chooser.IsInitialized = False Then
        chooser.Initialize("chooser")
    End If
    chooser.show("image/*", "Choose image")

Wait For(chooser) chooser_Result (Success As Boolean, Dir As String, FileName As String)

log(Dir)
log(FileName)

          
    Dim InputStream1 As InputStream
    InputStream1 = File.OpenInput(Dir, FileName)
    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
    SQL1.ExecNonQuery2("INSERT INTO table2 VALUES('smiley', ?)", Array As Object(Buffer))

sample code is based on this tutorial >> https://www.b4x.com/android/forum/threads/sql-tutorial.6736/#content
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
   Dim InputStream1 As InputStream
    InputStream1 = File.OpenInput(Dir, FileName)
    Dim OutputStream1 As OutputStream
    OutputStream1.InitializeToBytesArray(1000)
    File.Copy2(InputStream1, OutputStream1)
    Dim Buffer() As Byte 'declares an empty array
    Buffer = OutputStream1.ToBytesArray
Replace with:
B4X:
Dim Buffer() As Byte = File.ReadBytes(Dir, FileName)
 
Upvote 0
Top