9.2.1 Different Ways to Store and Access an Image

Typically, images are stored somewhere in the database, maybe as a Blob in a file, or a Bitmap or External Resource in the LANSA repository or it may just be a file somewhere on the Application Server. Whatever form it is saved in you need to access the image in the Server Module and assign it to a Blob to be passed to the requesting client.

SrvRoutine Name(GetImage)

Field_Map For(*output) Field(#xEmployeeImage)

Field_Map For(*output) Field(#xEmployeeImageThumbnail)

Field_Map For(*output) Field(#XEmployeeImageMidSize)

 

* set the BLOB content to file location

#xEmployeeImageThumbnail := 'C:\Users\User1\Pictures\LANSA\Employee00987tb.gif'

 

* set the BLOB content to an External Resource

#xEmployeeImage := #Employee00987.FileName

 

* set the BLOB content to a Bitmap

#xEmployeeImage := #EmpImage00987.FileName

 

Endroutine

 

Conversely, if you are on the Client and want to select an image to save to the database you will need to utilize the PRIM_WEB.FilePicker and may use something like this in your Web Page.:

Define_Com Class(#PRIM_WEB.FilePicker) Name(#FilePicker) Displayposition(3) Ellipses(Word) Height(56) Parent(#COM_OWNER) Tabposition(1) Tabstop(False) Top(6) Verticalalignment(Center) Width(169) Image(#xImageCamera32) Caption('Select an Image')

 

Define_Com Class(#PRIM_IMAG) Name(#Image) Displayposition(4) Left(191) Parent(#COM_OWNER) Tabposition(2) Tabstop(False) Top(6) Height(788) Width(800)

 

Define_Com Class(#PRIM_LABL) Name(#Filename) Displayposition(1) Ellipses(Word) Height(55) Left(197) Parent(#COM_OWNER) Tabposition(4) Tabstop(False) Top(733) Verticalalignment(Center) Width(800)

 

Evtroutine Handling(#FilePicker.FileSelected) File(#File)

 

Define_Com Class(#MyServerMod.SaveImage) Name(#SaveImage)

 

* Show the selected image on the page

#Filename := #File.Name

#Image.FileName #xDemoblob := #File.Blob

 

* Save the image to the database

#SaveImage.ExecuteAsync( #File.Blob )

 

Endroutine