Android Question Convert into inputstream from a contentChooser into database

ProjectGroup19

Active Member
Licensed User
Please, how do convert an image selected from phone storage into an inputstream. So that i can store it in my database.
 

ProjectGroup19

Active Member
Licensed User
B4X:
Dim bytes() As Byte = File.ReadBytes(Dir, FileName) 'event parameters

B4X:
Sub PP_Result(Success As Boolean, Dir As String, FileName As String)
    
    If Success = True Then
                Ppic.Bitmap = LoadBitmap(Dir,FileName)
        Dim bytes() As Byte=File.ReadBytes(Dir,FileName)
        Dim InputStream1 As InputStream=bytes
        Dim OutputStream1 As OutputStream

        OutputStream1.InitializeToBytesArray(1000)
        File.Copy2(InputStream1, OutputStream1)
        Dim Buffer() As Byte
        Buffer = OutputStream1.ToBytesArray
        Connection.db.ExecNonQuery2("UPDATE MEMBERSHIP set PIC= ? WHERE ACCOUNT='"&acc&"'", Array As Object(Buffer) )
    
                
    Else
        ToastMessageShow("Nothing Selected",True)
    End If
        
End Sub

error: incompatible types: byte[] cannot be converted to InputStreamWrapper
_inputstream1 = (anywheresoftware.b4a.objects.streams.File.InputStreamWrapper)(_bytes);
^

All im trying to do is; after selecting a picture in phone storage, then the selected picture is saved in the database.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
All im trying to do is; after selecting a picture in phone storage, then the selected picture is saved in the database.
Did you try something like this:
B4X:
    If Success  Then
        Dim Buffer() As Byte=File.ReadBytes(Dir,FileName)
        Connection.db.ExecNonQuery2("UPDATE MEMBERSHIP set PIC= ? WHERE ACCOUNT=?", Array As Object(Buffer, acc))
    Else
        ToastMessageShow("Nothing Selected",True)
    End If
 
Last edited:
Upvote 0

ProjectGroup19

Active Member
Licensed User
Did you try something like this:
B4X:
    If Success  Then
        Dim Buffer() As Byte=File.ReadBytes(Dir,FileName)
        Connection.db.ExecNonQuery2("UPDATE MEMBERSHIP set PIC= ? WHERE ACCOUNT=?", Array As Object(Buffer, acc))
    Else
        ToastMessageShow("Nothing Selected",True)
    End If
it worked perfectly. Thank you. :)
 
Upvote 0
Top