Uploading files to OCI Object Storage via APEX

Phantompete
Oracle Developers
Published in
3 min readDec 5, 2022

Introduction

In this guide you will learn how to integrate APEX and OCI Object Storage services. This will be done by executing a REST Request via a PL/SQL code block in APEX.

Before you can begin there is a set of pre-requisites listed below that have to be completed for you to smoothly progress through this guide.

Pre-requisites:

  • APEX Instance
  • OCI API Key
  • Object Storage Bucket

Authentication

1. Navigate to App Builder -> Workspace Utilities -> Web Credentials.

2. Create a new OCI credential using the details obtained from the OCI API Key and Save.

It is important to include the “Static Identifier” which will later be used to create the API request to Object Storage.

Note: Whenever you make a change the OCI Private Key needs to be re-added.

Upload Page

1. Create a blank page

2. Create a Region

3. Create a Page Item with type File Browse and a Button within the Region.

4. Configure the button action to Submit Page within the button parameters “Behavior” section.

Upload Process

Lastly, we add the processing that will enable us to upload the file to our Object Storage.

  1. In the Processing tab, create a new Process with the following parameters:

2. Paste the following PL/SQL Code within the “Source” section and adjust the following variables:

  • File Browse Page Item = “:FILE_NAME”
  • Object Storage URL = “https://objectstorage.eu-frankfurt-1.oraclecloud.com/n/namespace/b/bucket_name/o/”
  • Web Credential Static ID = “Your_Static_Credential_ID”
declare
l_request_url varchar(32000);
l_content_length number;
l_response clob;
upload_failed_exception exception;
l_request_object blob;
l_request_filename varchar2(500);
begin
select blob_content, filename into l_request_object, l_request_filename from apex_application_temp_files where name = :FILE_NAME;
l_request_url := 'https://objectstorage.eu-frankfurt-1.oraclecloud.com/n/namespace/b/bucket_name/o/' || apex_util.url_encode(l_request_filename);
l_response := apex_web_service.make_rest_request(
p_url => l_request_url,
p_http_method => 'PUT',
p_body_blob => l_request_object,
p_credential_static_id => 'Your_Static_Credential_ID'
);end;

3. Choose the previously created Upload button within the “Server-side Condition” section, “When Button Pressed”.

4. Save the page and run, you now have a fully functional utility that allows you to upload files to your Object Storage bucket.

That would be all for this guide, you can leverage this approach to create complex content management systems or upload singular images to free up the BLOB storage space within your database!

For more information you can find me on LinkedIn, and as always don’t forget to visit the Oracle APEX page for all your latest news.

--

--

Phantompete
Oracle Developers

New technologies, IoT & Blockchain enthusiast. Opinions expressed are solely my own and do not express the views or opinions of my employer Oracle.