How to store images into the database through forms
This is pretty easy. The answer is READ_IMAGE_FILE. The will read a file stored on the
machine with the form is executing. The image will become ‘visible’ on screen. When the
user saves into the database — the image will go into the database.
WRITE_IMAGE_FILE is what you would use to export an image that exists in the database to
the users machine. They would query a record up — get to the image they wanted and you
would give them a button or something to “export” the image. The when-button-pressed
trigger would invoke write_image_file to save the contents of the image to disk.
As a demonstration — I did the following:
scott@8i> create table image_table ( filename varchar2(255) primary key, image long raw
);
Table created.
I created a table that had a filename as the primary key and a image column to hold a
picture. I then created a default block on this table — using all of the defaults (just
pressed NEXT in the data block wizard and layout wizard, always selecting both columns).
So, I ended up with a form that had a IMAGE_TABLE block with columns FILENAME and IMAGE.
On this block I put a button. I coded a “when-button-pressed” trigger as follows:
read_image_file( :image_table.filename,
‘JPG’, ‘image_table.image’ );
I then ran this form. I typed into the filename field “c:\temp\tkyte.jpg” (thats a file
i had on my machine) and pressed the button. The contents of the file were displayed on
screen. I then did “action/save” to put the record into the database and commit. I then
did a “query/enter” to clear the block out and then “query/execute” to query up the
record I just put in there.
thats it…