Android Question Read image from Sql Server using Job1.PostString instead a cursor...

MarianoDuk

Member
Licensed User
Hello, i have some jpg images stored in a "image" field on sql server 2016 database.
I always conected to that database using Job1.PostString(ip of aspx parser file, the query i want to do i.e. SELECT IARCH FROM MYIMAGESTABLE)
I have read this sample in forum:

Sub ReadBlob
Dim Cursor1 As Cursor = SQL1.ExecQuery2("SELECT image FROM table2 WHERE name = ?", Array As String("smiley"))
Cursor1.Position = 0
Dim Buffer() As Byte = Cursor1.GetBlob("image")
Dim InputStream1 As InputStream
InputStream1.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
Dim Bitmap1 As Bitmap
Bitmap1.Initialize2(InputStream1)
InputStream1.Close
Activity.SetBackgroundImage(Bitmap1)
End Sub


But i dont know how to do the same, but using Job1.PosString query... In Jobdone i use a "map" variable to read the table fields, but i dont have something as "GetBlob".
Can someone help me? An example will be great! Please apologize my english.
Mariano.
 

MarianoDuk

Member
Licensed User
Please use [code]code here...[/code] tags when posting code.

Your best option is to switch to jRDC2.
Thanks Erel. Now i know wich is the best option. But I dont know jRDC2. So... it is posible to read and show and image stored on sql server using Poststring and Jobdone? Or it is imposible? Thanks
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
it isn't impossible or particularly difficult. the blob is downloaded like any other download. you re-assemble it on your end.

you need to know how the image was sent to the server and what the server did before storing it as a blob. you keep that in mind when you receive the stream. for example, was the image sent to the server as a b64 char stream? or perhaps, did the server convert it to b64 before writing the blob? if so, you need to convert the b64 string back to binary for restoring the image file. we don't know how the file was uploaded or what the server did. do you? if not, you may have to try a couple different ways. there really only are a couple. technically, downloading the blob is the easiest part. what you do when you receive it is the issue.

fyi: you shouldn't store images in the db. store a link to the image in the db as, eg, a text field. when you need the image, you load it and send it. much simpler than blob.

please fill in the missing information: how was the file uploaded, how do you tell the server what you want (how is the poststring formulated), etc.
 
Upvote 0

MarianoDuk

Member
Licensed User
it isn't impossible or particularly difficult. the blob is downloaded like any other download. you re-assemble it on your end.

you need to know how the image was sent to the server and what the server did before storing it as a blob. you keep that in mind when you receive the stream. for example, was the image sent to the server as a b64 char stream? or perhaps, did the server convert it to b64 before writing the blob? if so, you need to convert the b64 string back to binary for restoring the image file. we don't know how the file was uploaded or what the server did. do you? if not, you may have to try a couple different ways. there really only are a couple. technically, downloading the blob is the easiest part. what you do when you receive it is the issue.

fyi: you shouldn't store images in the db. store a link to the image in the db as, eg, a text field. when you need the image, you load it and send it. much simpler than blob.

please fill in the missing information: how was the file uploaded, how do you tell the server what you want (how is the poststring formulated), etc.

Thanks.
I stored images on database because it is more secure than have files alone in folders.
Finally i solve this situation in this way:

I created an asp page (it is very easy to query my table and convert image field on a jpg image in that web page) that receiv a parameter, that page reads image field and shows that images one after other, using this:

Response.ContentType = "image/jpeg"
Response.BinaryWrite rs("IARCH")

So, in my android app, i use a Webview that points to that asp page and sends parameter needed, and voilá! Works great!!!

Thanks Erel and DrGotTjr, this question is closed for me.
 
Upvote 0
Top