Wednesday, September 20, 2006

Oracle Application Express File Download

I recently had a client complain that when clicking on a file from an ApEx application it always asked them to save or open the file rather than just rendering it in the browser via a plug-in (e.g. rendering a pdf in Acrobat Reader).

I almost always want that, so it never seemed to be an issue to me, but I could see the point. I had utilized the standard ApEx routines for downloading files from a blob in my custom table. This has the following code:

htp.p('Content-length: ' || v_length);
-- the filename will be used by the browser if the users does a save as
htp.p('Content-Disposition: attachment; filename="' || v_file_name || '"');
-- close the headers
owa_util.http_header_close;
-- download the BLOB
wpg_docload.download_file( Lob_loc );


This code is fine and it does just what it will do, but the blue text causes (at least some, including IE) browsers to force a download, and never open within the browser.

It was easy to comment out that line, but that left another issue. Now when the user does a save (right clicks and does "Save as" or saves from the plugin) it doesn't have the correct filename. It will have as a filename whatever comes after the last slash (/) in the url. That probably looks something like my_package.download?p_id=12442. Users really didn't like that.

So . . . What to do? We changed the download links to look like this instead:
/apexfiledownload//
like this
/apexfiledownload/12442/myFile.pdf

Then we used an Apache rewrite rule to route that to our download routine (my_package.download?p_id=12442). Here is the rule:

RewriteRule ^/apexfiledownload/([^/]+)/?(.*) /htmldb/my_package.download?p_id=$1 [PT]

That works and everyone is happy now.

I have an idea that I could also have implemented this by simply changing the offending line from attachment to inline:
htp.p('Content-Disposition: inline; filename="' || v_file_name || '"');
Testing that will be left to another day.

Thursday, September 14, 2006

Always something to do during a con-call


Just to show that there is more to do than Oracle . . . I was recently on a long con-call. And you can always find something to do during a long con-call. I had to switch phones to make the call because a couple of the keys on my cordless Motorola phone (md400 series) had stopped working. It happened over time, becoming more and more annoying until a few just don't work at all. Of course, the "1" doesn't work--and I live in the Boston area, where you need to dial a 1 to call next door. So, I grabbed another phone, dialed the call-in number, and got to work.

The hardest part, of course, is to just get the darn thing apart. At least nothing was glued together. It just required some prying and determination (and removing a few screws, 2 obvious, 2 hidden under a panel).

Then off to figure out the problem. The contacts were all good, and the keys all looked the same, but a few just wouldn't cause the contacts to connect.

So, I added a little piece of aluminum foil over each key and reassembled (you can see the first five in the picture). Now it works great, maybe a little too easy to get a number, but I suspect that will change over time. Now I don't need to buy a new phone, and it didn't take me any time because I was on a con-call.