Display Image From Database Without Creating Physical File

Forum to discuss the Web client version of Servoy.

Display Image From Database Without Creating Physical File

Postby ayadav1 » Thu Oct 20, 2016 2:59 pm

Hi Everyone,

I have one web application where I need to display some images from database. In database those images are stored in byte format. Currently, I have implemented a method to convert byte array into physical file then using that physical path I am displaying images.

I do not want to create physical file. Without creating any temp file I want to display image.

When retrieving data from database then its not the same format as it was in database.

Database Format:

"\377\330\377\340\000\020JFIF\000\001\001\001\000`\000`\000\000\377\341\000\366Exif\000\000MM\000*\000\000\000\010\000\010\001\032\000\005\000\000\000\001\000\000\000n\001\033\000\005\000\000\000\001\000\000\000v\001(\000\003\000\000\000\001\000\002\000\000 (...)"

Servoy Format:

[-1,-40,-1,-32,0,16,74,70,73,70,0,1,1,1,0,100,0,100,0,0,-1,-37,0,67,0,3,2,2,3,2,2,3,3,3,3,4,3,3,4,5,8,5,5,4,4,5,10,7,7,6,8,12,10,12,12,11,10,11,11,13,14,18,16,13,14,17,14,11,11,16,22,16,17,19,20,21,21,
21,12,15,23,24,22,20,24,18,20,21,20,-1,-37,0,67,1,3,4,4,5,4,5]

I am trying to get actual (raw) data from database which is in binary format then I will convert it into base64 format. Then I can use it directly to display the image without creating physical file.

Anyone has an idea to get RAW data from database. Because if I get the RAW data then I will convert it into base64 string and directly I will pass this string to <IMG> src tag to display the images.


Thanks in advance!
ayadav1
 
Posts: 13
Joined: Thu Oct 20, 2016 2:40 pm

Re: Display Image From Database Without Creating Physical Fi

Postby Andrei Costescu » Thu Oct 20, 2016 3:20 pm

But isn't that really the raw data (each number in there seems to be a byte)?
Didn't you use that array to write bytes to the file and it worked?

Doesn't it work if you just use that column as a dataprovider for image components?
Andrei Costescu
Servoy
Andrei Costescu
 
Posts: 902
Joined: Tue Jun 26, 2007 3:14 pm

Re: Display Image From Database Without Creating Physical Fi

Postby ayadav1 » Fri Oct 21, 2016 3:34 pm

Hi Andrei,

Thanks for your response.

RAW data means actual database format. Because If I convert the Servoy byte format to base64 then I will not be able to get the image data.

That is why I am trying to get database format data in servoy application. In that way I can play with those data.

Thanks
ayadav1
 
Posts: 13
Joined: Thu Oct 20, 2016 2:40 pm

Re: Display Image From Database Without Creating Physical Fi

Postby Andrei Costescu » Fri Oct 21, 2016 9:55 pm

I don't get it. What type does the column have in the DB? Is it actually a string like you pasted in the first post?

If you already have a method that converts whatever you get from the DB into bytes that represent an image file (the same bytes you need now right?) - why not use that as a global method converter on the DB column (open your table in table editor, click on column then select last tab "Conversion"). There you can specify 2 global methods that convert between the database data and what will be used in Servoy. So DB data goes to converter method that returns the value that will be used in Servoy.

I still think you should make it somehow so that that column can be used directly as a dataprovider to display the images.
Or do you want/need to use something special to display the image instead of the default servoy provided components?

Maybe you can make an example (byte by byte) of each step the data needs to go through (and the value in each step) from DB to being displayed (including DB and how it will be displayed)
What type of client do you use?
Andrei Costescu
Servoy
Andrei Costescu
 
Posts: 902
Joined: Tue Jun 26, 2007 3:14 pm


Return to Servoy Web Client

Who is online

Users browsing this forum: No registered users and 1 guest