 |
|
Oracle Database Tips by Donald Burleson |
Using APEX
to
Create the
File Browse…
Item
1.
Click the icon
in the Items area.
2.
On the Item Type page, choose the File Browse option and click
Next.
3.
On the Display Position page:
·
Item Name: P1090_NAME
·
Sequence: 10
·
Region: Image Upload
·
Click Next.
4.
On the Item Attributes page:
·
Label: Image File Name.
·
Field Width: 80
·
Click Next.
5.
On the next page click on the Create Item button.
Create the Upload
Button
Now it is time to provide a button to submit the
page. The file will be uploaded when the page is submitted.
1.
Click the icon
in the Buttons area.
2.
On the Button Region page, click Next.
3.
On the Button Position page, choose the Create a button in a
region position option and click Next.
4.
On the Button Attributes page, enter UPLOAD for the Button Name
and click Next.
5.
On the Image Attributes page, click Next.
6.
On the Display Properties page, click Next.
7.
On the Branching page enter &APP_PAGE_ID. for the Branch to
Page field and click Create Button. Remember the ending period!
Create the Copy Image
Process
This process is going to move the record inserted
into the wwv_flow_files view over to the new easy_image table.
1.
Click on the icon
in the Processes area of the Page Processing region.
2.
On the Process Type page, choose the PL/SQL option and click
Next.
3.
On the Process Attributes page:
·
Name: Copy Image
·
Sequence: 10
·
Point: On Submit - After Computation and Validations
·
Click Next.
4.
On the Process page, enter the following for the PL/SQL Page
Process and click Next. The full text can be found in file
copy_image_process.sql in the online code depot.
begin
--
-- When an image is uploaded it is stored in the
-- FLOW_FILES.WWV_FLOW_FILE_OBJECTS$ table.
-- The wwv_flow_file_objects$ table is identified
in the dads.conf
-- file in the PlsqlDocumentTablename
parameter.
-- WWV_FLOW_FILES is a view to this table.
--
-- We want to keep the image in our own table.
-- Copy the image from WWV_FLOW_FILES to our own
EASY_IMAGE table.
--
insert into easy_image(
image_id, name, filename,
mime_type, doc_size, created_by,
created_on, content_type, blob_content )
select id, name, filename,
mime_type, doc_size, created_by,
created_on, content_type, blob_content
from wwv_flow_files
where name = :P1090_NAME;
--
-- Now that we have copied the image to our own EASY_IMAGE table
-- delete it from the WWV_FLOW_FILES table. That way we can keep
-- the files from growing too much in the WWV_FLOW_FILES and make
-- it easier for use to make backups of our data.
-- Deleting the record is done by referencing the NAME column.
-- When the file is uploaded the P14_NAME page item will be set
to
-- the value of NAME that was put into the WWV_FLOW_FILES table
-- and we can use it for reference.
--
delete from wwv_flow_files where name =
:P1090_NAME;
end;
5.
On the Message page:
·
Success Message: Image successfully loaded.
·
Failure Message: Image could not be loaded.
·
Click Next.
6.
On the Process Conditions page:
·
When Button Pressed: Select the UPLOAD item.
·
Click Create Process.
The page to upload an image is now complete. Run
the new application page and take a look. The finished page is shown
in Figure 9.1 with the Image File Name filled in.
Uploading an Image
On the newly created application page, click on
the Browse… button and navigate to the C:\htmldb_book\CodeDepot\images\niagara_falls.jpg file. After selecting
the file, click the Upload button.
The following is going to happen when the button
is clicked:
·
The application page is submitted and the fact that is
being submitted by pressing the Upload button is stored in the HTML
request as UPLOAD.
·
The image is automatically inserted into the
wwv_flow_files view.
·
When the image is inserted the P1090_NAME page item will
be set to a value of F22557/niagara_falls.jpg. NOTE: the F22557 will
be different on each system. Since the wwv_flow_files has a unique
index in the NAME column, the value in the P1090_NAME page item can be
used to select information about the image that was just inserted.
·
The page process Copy Image will be executed to move the
image record to the EASY_IMAGE table. The process is executed on the
condition of the UPLOAD button being pressed. Also, the process uses
the P1090_NAME page item in the SQL statements to copy the image.
·
The page will be rendered and the results will be
displayed.
The above book excerpt is from:
Easy HTML-DB
Oracle Application Express
Create
Dynamic Web Pages with OAE
ISBN 0-9761573-1-4
Michael Cunningham & Kent Crotty
http://www.rampant-books.com/book_2005_2_html_db.htm |