Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 7 of 7 total
Thread How to store an image in a blob field
Thu, Jan 2 2014 12:08 PMPermanent Link

Uli Becker

Hi,

I am loading a picture into a TImage component by assigning the URL to
TImage.ImageName.

How can I store this image in a blob field?

Thanks Uli
Fri, Jan 3 2014 3:14 AMPermanent Link

Uli Becker

Addition:

and how to get an image from a TBlob field (EDB-table)?

I use a self made server and don't know how to create a json-file
regarding the blob field. Does anyone have some code snippets that could
help?

Thanks Uli
Fri, Jan 3 2014 7:00 AMPermanent Link

Walter Matte

Tactical Business Corporation

Uli:

Since you are writing your own Web Server (and I have written my own using RealThinClient) ... to take advantage or EWB behaviour we will have to emulate or design similar mechanisms to what Tim's server does....

I looked at the CDCollector sample and the EWB Server Documentation.

The EWB framework requires the database table with the embedded graphics to have a related field with the same name + __ContentType.  (same applies to TPlug - if you want audio or mpg).

In the  CD Collector example album cover art fields in table are:

CoverArt  (blob field)
CoverArt_ContentType (contains 'image/png')

In the CD example the TImage component DataColumn is associated to the field CoverArt.

The JSON dataset sent to the browser contains a URL.  (See attached png - it is a Fiddler Debug of running the CDCollector example.)

Here is what is in the JSON data being sent to browser for the field CoverArt:

CoverArt=datasets/Albums?method=load&column=CoverArt&row=1

After the dataset load, the TImage component issues a request for the graphic.

When I navigate to the next record and the TImage again issues a request for the graphic. (you can see in screen shot attached.)

I'm not an expert... but isn't this is how 'web pages' work.....  graphics are references to files and when browsers read the web page, they know to go back and fetch the associated graphics...

To emulate this behaviour - you will need to send a URL in the JSON for graphic fields and your web server needs to respond to the graphic request and pull it out of the DB and send it with the correct content type.

Walter Matte



Attachments: EWB_Blob.png
Fri, Jan 3 2014 7:26 AMPermanent Link

Uli Becker

Walter,

many thanks for this detailed explanation!

BTW:
CoverArt_ContentType (contains 'image/png')

Where did you find that in the manual? I use the help within the  IDE
but didn't find anything about TImage -> Blob.

Best regards Uli
Fri, Jan 3 2014 7:35 AMPermanent Link

Walter Matte

Tactical Business Corporation

Uli:

TImage - Blob in manual - no - I just guessed and watched the behaviour in Fiddler....

I didn't really find it all in the manual... I had to look at the database table structure and then - I guessed about the Field_ContentType - and then later found the reference.  It was the Web Server documentation for EWB - TEWBDataSetAdapter - GetLoadContentType

http://www.elevatesoft.com/manual?action=viewmethod&id=ewb1mod&product=rsdelphi&version=XE&comp=TEWBDataSetAdapter&method=GetLoadContentType

I saw 'image/png' from looking at the actual data in the table which comes with the CD Example - it is a DBISAM table.... Albums.dat.

This was all good... I will need to build this in my web server too!

Walter
Fri, Jan 3 2014 7:41 AMPermanent Link

Walter Matte

Tactical Business Corporation

....

Field_ContentType  .... The CDCollector example used 'image/png' beause the graphics with PNG's .... you would of course record the right content type for the type of content in the blob... for example JPEG you would use content type 'image/jpeg'

Walter
Fri, Jan 3 2014 7:46 AMPermanent Link

Uli Becker

Walter,

> TImage - Blob in manual - no - I just guessed and watched the behaviour in Fiddler....
>
> I didn't really find it all in the manual... I had to look at the database table structure and then - I guessed about the Field_ContentType - and then later found the reference.  It was the Web Server documentation for EWB - TEWBDataSetAdapter - GetLoadContentType

Good investigation!

Uli
Image