Using APplication EXpress as a simple GUI cover for Matadata based generators of XML and SQL files led me to task to download these files.
Browsing over various helps I decided to add another one to the rubbish.
There are two basic scenarios:
1. We want to download result of PL/SQL method (function) directly
to client machine, or
2. We want to download generated codes from stage - some storage of files prepared for download.
1. Direct download of generated code
Create new page dedicated to download file.
Create items - parameters necessary for the generating process and filename.
Create following process. The process can be situated After Regions. That arrangement allows to do computations on the page before.
The download should be initialized by redirecting to this pages and setup of necessary page items. After the file is downloaded, the process will return back to the calling page.
2. Prepare files for download
Differently from the first case we can download files stored as BLOB fields in database table.
The way of asynchronous preparing of data for download in database table is more efficient especially when the time of generating is significant. You can let the system to generate your code on background and not to waste your time waiting for your files.
The mentioned way also allows to prepare several files to be downloaded at once.