This document explains how to upload and download images from the database 
using Oracle Application Server 4.x. 
SCOPE & APPLICATION
===================
 
The information in this document is intended for users who want to upload 
images or files and store them into the database for future downloads.
Oracle Application Server lets you upload image files and other files into your 
database. These files can be downloaded to your browser through content 
services provided by the PL/SQL toolkit. When you upload the files into 
database it stores the file in websys.owa_content table. Other details like the 
file name are stored in websys.ows_object table. For simple upload and download 
of files, you do not have to access these tables directly.Ensure that when you install the PL/SQL toolkit all the owa_content packages 
are installed without any errors. If you have any doubts, there is no harm 
in reinstalling the PL/SQL toolkit and reconfirming.
Follow these steps to upload and download images or files into the database:1.  Create a directory called static. The path for this directory can be 
    D:\static2.  Cut and copy the following html text into a file called upload.htm.    <html>
    <head>
    <title>This form is used for uploading files into database</title>
    Choose the file you want to upload into your database
    </head>
    <body>
    <p>
    <FORM
    enctype="multipart/form-data"
    action="/file/websys.write_info"
    method="POST">
    <p>File to upload:
    <INPUT type="file" name="file"><br>
    <p>
    <INPUT type="submit">  
    </body>
    </html>3.  Add the following entry in the listener directory configuration.        File-System Directory   Flag       Virtual Directory     
        D:\static\              NR         /static/     Click on Apply.
4.  In OAS create a DAD, an application, and a cartridge. For information on 
    how to create an application and a cartridge, refer to the tutorial in 
    online documentation. Let the virtual path be /file.  5.  Cut and copy the following text into a file called write_info.sql:    create or replace procedure write_info (file in varchar2) as
     begin
        htp.htmlopen;
        htp.headopen;
        htp.title('File Uploaded');   
        htp.headclose;
        htp.bodyopen;
        htp.header(1, 'Upload Status');
        htp.print('Uploaded ' || file || ' successfully');
        htp.bodyclose;
        htp.htmlclose;
     end;
    /6.  Cut and copy the following text into a file called down_form.sql:    create or replace PROCEDURE down_form IS
    list_val varchar2(100);
       BEGIN
         htp.htmlOpen;
         htp.headOpen;
         htp.title('Adding New Employee');
         htp.headClose;
         htp.bodyOpen;
         htp.centerOpen;
         htp.header(1,'This Form Can be Used To Download Files from database');
         htp.para;
         htp.img(curl=> '/ows-img/ows.gif');
         htp.centerClose;
         htp.para;
         htp.formOpen(owa_util.get_owa_service_path||'websys.down');
         htp.para;
         htp.p('File Name ');
         htp.formSelectOpen('file_val','Select the file you want to download ');
       Declare  
         CURSOR load_list_cur IS
         select name from ows_object;
       begin
       OPEN load_list_cur;
       LOOP
          FETCH load_list_cur into list_val;
             EXIT WHEN load_list_cur%NOTFOUND;
             htp.formSelectOption(list_val);
             htp.nl;
       END LOOP;
       close load_list_cur;
       end;
       htp.formSelectClose;
       htp.para;
       htp.para;
       htp.formSubmit;
       htp.formReset;
       htp.formClose;
       htp.bodyClose;
       htp.htmlClose;
       END down_form;
       /7.  Cut and copy the following text into a file called down.sql:    create or replace PROCEDURE down(file_val VARCHAR2) IS
       l_ext VARCHAR2(100) := NULL;
       l_mime_type   VARCHAR2(100) := NULL;
       BEGIN
       l_ext := substr(file_val, instr(file_val, '.', -1));
       IF UPPER(l_ext) = 'PDF' THEN
          l_mime_type := 'application/acrobat';
       ELSIF UPPER(l_ext) = 'GIF' THEN
          l_mime_type := 'image/gif';
       END IF;
       IF l_mime_type IS NOT NULL THEN
          owa_util.mime_header(l_mime_type);
       END IF;
          htp.download_file(file_val);
       END down;
       /8.  Now log into SQL*Plus: 
    userid  : websys
    password: manager
   
    compile the 3 sql files which you created using the following command
    @write_info.sql
    @down_form.sql
    @down.sql
  
    Grant the following roles to the DAD_USER by executing the following command.    grant execute on websys.owa_content to <DAD USER>
    grant execute on websys.ows_cs to <DAD USER>
   
    Grant execute privileges of all the procedures you created to the DAD USER by
    using the following commands.  
    
    grant ows_standard_role to <DAD USER>
    grant execute on write_info to <DAD USER>
    grant execute on down_form to <DAD USER>
    grant execute on down to <DAD USER>
 
9.  Reload your WebServer.10. From your browser access the following URL:    http://HostName.DomainName:Port/static/upload.htm    Select the file you want to upload. Click on Submit. You should get
    a message file uploaded successfully. At this point the file is
    uploaded into websys.owa_content table and the other information is 
    stored in websys.ows_object table. You can verify the upload by 
    doing a select query.11. From your browser access the following URL:
    
    http://HostName.DomainName:Port/file/websys.down_form
    
    This lists all the files you have uploaded until now. Select the file
    you want to download. Click on Submit. You would see that the depending 
    on the file you downloaded, it would show you the contents. If it is an 
    image file, then the image would display on your browser.