SQLite and Audio Blob... possible?

NFOBoy

Active Member
Licensed User
Longtime User
Ok, want to try and use the power/flexibility of SQL to store required file information.

Currently, am using a simple .csv, with required audio clips parsed out, that are associated with each record.

I have looked through and determined that using a Blob is technically possible to store practically any information in an SQL (many examples for images I have found).

However, have not found a way to convert audio clips for storage and retrieval inside an SQLite database.

I could just store the name of the audio clip (and then have the audio files separate from the database, which is what I am doing now) , but would be nice if it could actually be imbedded in the database.

Is this actually possible (vice just technically... for my slow brain)

Thanks,

Ross
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Yes. You can store any file in a BLOB field.
You can use this method to get the required bytes array:
B4X:
Sub GetBytesFromFile(Dir As String, FileName As String) As Byte()
   Dim out As OutputStream
   out.InitializeToBytesArray(100)
   Dim in As InputStream
   in = File.OpenInput(Dir, FileName)
   File.Copy2(in, out)
   Return out.ToBytesArray
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…