Migrating Apex images from apache to EPG

I've recently been involved in a migration from Apex 3.2 (or htmldb as it was back then) to 4.2 over the past few days. This has proved an 'interesting' experience - I've certainly picked up a lot and thought i'd share some of it.

The 3.2 installation has happily been using apache (or oracle http server as it seems to get called) for a number of years with no problems. However we thought we'd simplify things as part of the migration to use the EPG option.

For those of you who are wondering what I'm talking about (as this would have made little sense to me a couple of weeks ago) there are 3 options for running the 'web server' part of APEX:

1. Apache
2. EPG (embedded plsql gateway)
3. Apex listener

1. is easy enough and should be very familiar to everyone
2. uses database functionality (spcifically xmldb and the DPME_EPG package to actually host the webserver out of the database itself - the database will register with the listener on a http port you define and you actually route web connections through the listener - clever eh?
3. Relies on some middleware to be installed and running don;t know if thats weblogic/glassfish etc and what is required - it seemed more complex so we went with the nice and simple option 2.

So anyway back to what i was going to share. The application we migrated had some image files displayed on the screens, these were served from the images directory underneath apache. Now we are using EPG we of course can;t use anything under the apache tree and have to somehow get the images into the database so that APEX can access them from there (this works in a similar way to the way you can do images uploaded through APEX itself).

The virtual /images directory has already been created inside the xmldb repository by the APEX 4.2 install - so all we need to do is upload the file into this xmldb location. This is actually very simple and only needs this small piece of code below:

First we create a temporary directory (this is only needed as a means to load the file in the first place - it can be removed afterwards)

create directory upload as '/oracle/Apache/Apache/instances/instance1/config/OHS/ohs1/images';





Then we load the file from /oracle/Apache/Apache/instances/instance1/config/OHS/ohs1/images/rmds.gif

declare
  content_bfile bfile;
  result        boolean;
begin
  content_bfile := bfilename('UPLOAD', 'rmds.gif');
  result        := xdb.dbms_xdb.createresource('/images/rmds.gif',
                                               content_bfile,
                                               nls_charset_id('AL32UTF8'));
end;
/


And that's it as simple as that - the app works happily and the image appears on all the screens


0 comments:

Post a Comment