APEX 5 zip file support

In this blog we’ll explore support for ZIP files within APEX 5 which listed as one of the “Additional Features” on Oracle’s newly released APEX 5 Early Adopter 3 edition.

We’ll first explore how Zip files can be uploaded to and downloaded from the Static Application Files area of the shared Components and then demonstrate how you can use the same functionality in your applications.

We’ll start the first exercise with a Zip File called Files.zip which contains A_File.txt and B_File.txt. We’ll also use C_File.txt which is not zipped.

Within the Static Application Files area of the shared Components; click on Upload File and we are asked to supply file details.

upload-file

APEX 5 supports Directories; therefore you can create a new directory here or upload in to Root using the popup LOV. In this example we’ll create a Directory called Demo Files. Choose Files.zip in the File field, then set “Unzip File” to Yes and click the “Upload and Upload Another” button. Do the same for C_File.txt but upload it to Root and click the “Upload” Button.

c_file

What we see above is the Zip file extracted in to a new Directory called Demo Files (Note that the name of the zip file is not used). A “forward slash” notation is also used indicating the Directory Names. We’ll revisit this again towards the end of this blog.

As you can see all the files from root and sub directories are mixed together; we can format this a bit better by adding a new computation column to the Interactive Report called Folder Name with the expression:

If we ensure Folder Name is a Selected Column and set it as a Control Break, we can then see a better looking file directory listing which you can also save as a Named Report:

named-report

By now, you’ll have noticed the Download as Zip button next to the Upload File Button; give that a click and you’ll see all three files downloaded as a zip containing C_File.txt and a sub folder of Demo Files using the forward slash notation, Containing A_File.txt and B_File.txt. (Note that the Download as Zip button downloads all files and does not observe the Interactive Report filters).

Integrating Zip functionality in to Applications

APEX 5 comes with a new package called APEX_ZIP containing 4 modules; so let’s try these out and integrate this in to our application.

Create a new Page and two Classic Report Regions as below:

Create 2 Region buttons in the Static Files region called ZIP (submits the page) and DOWNLOAD (Redirects to Page &APP_PAGE_ID. with a Request of DOWNLOAD).

Create a process called Zip Process in the Processing Section with a condition that the Zip button is pressed.

So the above demonstrates zipping all the files we’ve previously uploaded in to shared objects into a single zip file and stores it away in a collection called ZIP_COLLECTION. It then extracts each file and stores the name and content in another collection called UNZIPPED_FILES_COLLECTION.

So when we run the application, and click the Zip button we can see each of the files has been zipped and then unzipped in to the Unzipped Files Classic Report Region.

Each file has also been prefixed with a new Directory name called Top Level Directory.

zip-support

We will now add some code to download our Zip file which we have already stored in ZIP_COLLECTION.

Add a Before Header Process called Download and we’ll add a Request = Value condition with a value of DOWNLOAD.

Give the Download button a click now and your Zip file, called My Files.Zip, will download to your browser download location. Open up the file and you’ll see that the new forward slash directory notation has been observed and contains a folder called Top Level Directory containing a file called C_File.txt and a sub folder called Demo Files which contains A_File.txt and B_File.txt

demo-files

In Summary APEX 5 through the package APEX_ZIP provides basic support for zipping and unzipping Zip files. In this blog we demonstrated all the available Zip functions that APEX provides.

Files can then be managed in your APEX session and downloaded to the user’s desktop. This will be extremely useful if the user wishes to download multiple files or upload just a single zip file.

Matt Mulvaney Author
Senior Oracle APEX Development Consultant , Explorer UK Ltd

Matt is an experienced APEX solution designer having designed numerous complex systems using a broad range of Oracle Technologies. Building on his previous experience of Oracle Forms & PL/SQL, he is entirely focused on providing functionally rich APEX solutions. Matt promotes APEX as a software platform and openly shares best practises, techniques & approaches. Matt has a passion for excellence and enjoys producing high quality software solutions which provide a real business benefit.

follow me