Hi all,
I have a web service that delivers, in JSON format, records that contain integer and text values as well as a BLOB field from a SQL Server db. The SQL field data type is varbinary(MAX).
The BLOB contains a photo image, in the original JPEG format.
I've been reading the forum for this topic, but not finding exactly what I need to do, which is 2 things...
1) Web Service Call:
From the B4A app, call a web service that delivers back the JSON formatted data, parse the data, and write each record to a sqlite database. This all works well, but I'm not sure how to define the image variable (Picture) in the parsing code.
The Picture variable is defined as: Dim Picture as String.
The code updates the variable: Picture = colitems.Get("Picture").
Then a write to the database: SQL.ExecNonQuery(strSQL, Array as Object(ID, Picture))
This code works fine.
Using a SQLite Browser app on the tablet, I see the Picture field data without any seeible issue - a bunch of characters.
2) Set the layout ImageView object with the Picture field from SQLite DB:
I have a code module that I call from the Activity module to get explicitly the BLOB value from the record as:
But as you can see, the bmp.Initialize2(ipstrm) fails.
What is the best way to do all this?
BTW: we do not have WI-FI as an option during the web service call.
ADDED: What I mean is, the downloading (PostString) of the data happens when the tablet is connected to the network via a mini USB and RJ45 cable. The user will then enter data on the tablet, which is stored in the local SQLite database. When the user is finished, they reconnect the tablet and the upload transfers the new data to the SQL Server db.
Thanx,
Mark Stuart
I have a web service that delivers, in JSON format, records that contain integer and text values as well as a BLOB field from a SQL Server db. The SQL field data type is varbinary(MAX).
The BLOB contains a photo image, in the original JPEG format.
I've been reading the forum for this topic, but not finding exactly what I need to do, which is 2 things...
1) Web Service Call:
From the B4A app, call a web service that delivers back the JSON formatted data, parse the data, and write each record to a sqlite database. This all works well, but I'm not sure how to define the image variable (Picture) in the parsing code.
The Picture variable is defined as: Dim Picture as String.
The code updates the variable: Picture = colitems.Get("Picture").
Then a write to the database: SQL.ExecNonQuery(strSQL, Array as Object(ID, Picture))
This code works fine.
Using a SQLite Browser app on the tablet, I see the Picture field data without any seeible issue - a bunch of characters.
2) Set the layout ImageView object with the Picture field from SQLite DB:
I have a code module that I call from the Activity module to get explicitly the BLOB value from the record as:
B4X:
'Activity call to get the image:
ivPicture.Bitmap = DBCalls.GetAnimalProfileImage
'the DBCalls code module handler to return the image:
Sub GetAnimalProfileImage As Bitmap
Dim Buffer() As Byte
Dim strSQL As String = "SELECT Picture FROM AnimalProfile WHERE AnimalID=" & Starter.AnimalID
Dim cr As Cursor
cr = SQL.ExecQuery(strSQL)
cr.Position = 0
If cr.RowCount > 0 Then
Buffer = cr.GetBlob("Picture")
Dim ipstrm As InputStream
ipstrm.InitializeFromBytesArray(Buffer,0,Buffer.Length)
Dim bmp As Bitmap
bmp.Initialize2(ipstrm) 'fails here with: java.lang.RuntimeException: Error loading bitmap.
ipstrm.Close
End If
cr.Close
Return bmp
End Sub
But as you can see, the bmp.Initialize2(ipstrm) fails.
What is the best way to do all this?
BTW: we do not have WI-FI as an option during the web service call.
ADDED: What I mean is, the downloading (PostString) of the data happens when the tablet is connected to the network via a mini USB and RJ45 cable. The user will then enter data on the tablet, which is stored in the local SQLite database. When the user is finished, they reconnect the tablet and the upload transfers the new data to the SQL Server db.
Thanx,
Mark Stuart
Last edited: