Oracle APEX 23.2 - Store Static Resources in Object Storage

Introduction

A few days ago, I was looking at the What's New page again for 23.2 and I noticed something that I totally missed, the ability to store Static Resources in Object Storage instead of the traditional Shared Component location

Screenshot of the what's new page showing the feature announcement

The main advantage is that you can deploy a new version of you JavaScript/CSS files without having to deploy the application again.

But let see how to make it working

Oracle Cloud Configuration

As mentioned before, the idea is to store the files in an OCI bucket and to do so, you will need an OCI account, if you haven't then go to cloud.oracle.com and register for a free tier

User

We have to set up a user that the Oracle APEX builder will use to communicate with the OCI Object Storage REST API.

To create one, open the menu, go to Identity & Security and, under Security, click on Users. On that page, click on the Create User button and fill the form with the following information:

  • Name: APEX_FILES_Service_Account

  • Description: Service account for Oracle APEX application files

Screenshot of the create user page in the OCI console

When it's done, edit the user and click on the Edit User Capabilities and make sure that only API Keys is checked.

Screenshot of the edit user capabilities page in the OCI console

Then, under resources, click on API Keys and Add API Key, leave the default values, download the private and public key and click the Add button.

Screenshot of the add API key page in the OCI console

On the confirmation screen, please take note of the user, fingerprint and tenancy values

Group

Then we have to set up a group, go back to Identity & Security and, under Security, click on Groups. On that page, click the Create Group button and fill the form

  • Name: APEX_FILES_Security_Group

  • Description: Security Group for Oracle APEX files

Screenshot of the create group page in the OCI console

Edit the group and, under Group Members, click the Add User to Group button. Select the user created previously and click Add

Screenshot of the add user to group page in the OCI console

Compartment

We will create a new compartment in which the bucket will be created. It's a good practice, because we will later assign permission to this compartment only.

Open the menu, go to Identity & Security, and, under Security, click on Compartments. In this page click on the Create Compartment button and fill the form

  • Name: APEX_STATIC_FILES

  • Description: APEX Static Files

Screenshot of the create compartment page in the OCI console

When the compartment is created, under Compartment Information, copy the OCID, it will be used when we will set up the Oracle APEX configuration.

Screenshot of the edit compartment page in the OCI console

Policy

The policy will give permission to the group to manage buckets in the compartment, to do that, go to Identity & Security again and click Policies. On that page, click the Create Policy button.

Fill the form this way

  • Name: APEX_FILES_Policy

  • Description: Policy for Oracle APEX Files

  • Compartment: APEX_STATIC_FILES

Under policy Builder, in the Policy use cases, select "Storage Management" and in the Common policy templates, select "Let Object Storage admins manage buckets and objects"

Select APEX_FILES_Security_Group under Groups and APEX_STATIC_FILES under location and click Create

Screenshot of the create policy page in the OCI console

Bucket URL

The last thing we have to know is our bucket base URL, and it's a little tricky, the URL is construct this way

https://objectstorage.{regionIdentifier}.oraclecloud.com/n/{namespaceName}/b/{bucketName}/

  • regionIdentifier can be found in your OCI console top bar by clicking on Manage regions

    Screenshot of the top menu in the OCI console

    Screenshot of the manage regions page in the OCI console

  • namespaceName can be found by opening the menu, click on Governance & Administration then Tenancy details. On that page, you should see the Object storage namespace

    Screenshot of the tenancy details page in the OCI console

Oracle APEX Configuration

Now that everything is configured on the OCI side, we have to set up the Oracle APEX application to use the OCI bucket to store the application files.

Creation Wizard

Open the application definition and scroll to the Application File Storage

Screenshot of the Application Definition in the Oracle APEX Builder

Click the Add Object Storage button, if you don't have any OCI web credentials, then you should see this

Screenshot of the add remote storage showing missing credential in the Oracle APEX Builder

Click Create Credential and fill the form with the information from the OCI part and click Create.

In the Application Definition, click on Add Object Storage again and you should now see this

Screenshot of the Add Remote File Storage in the Oracle APEX Builder

Fill the form

  • Name: I leave the default value which is {APP_ID}_BUCKET

  • Bucket URL: refer to the OCI section above, but after a brief exchange with the Oracle APEX development team on the forum, it appears that you have to specify the bucket name in it

  • Create bucket: it depends if you want to create a new bucket or not

  • OCI Credential: select the one you just created

  • Compartment OCID: refer to the OCI part

Click Next and you should see

Screenshot of the Add Remote File Storage in the Oracle APEX Builder

Click Finish to Migrate the files to the Object Storage and voila, the bucket is created and the files synchronized 🤩

Synchronizing the files

Go to Shared Components, Static Application Files and you will notice that your files are now stored in the Object Storage on the right

Screenshot of the Static Application Files in the Oracle APEX Builder

Click on the Synchronize Files link under Tasks and you will have the ability to choose whether you want to synchronize from Object Storage to Local Database or from Local Database to Object Storage.

Click the Synchronize Files button and it's done. Simple and effective!

Updating the File Server

If one day you want to update the file server attributes, there are not accessible from the Application Definition but you can find them under App Builder, Workspace Utilities, All Workspace Utilities

Screenshot of the top menu bar in the Oracle APEX Builder

On that page, click on Remote Servers and you fill find them.

Conclusion

In this blog post, we have seen how to set up an Object Storage to store Static Application Files in an OCI bucket but also how to synchronize the files between the two and even how to update the File Server attributes.

In my opinion, this is a really good features and the implementation is simple and effective. I would also like to thanks Jayson Hanes and Neil Fernandez for their prompt support in the forum while working on this blog post.

Resources