Moving Files Out of the Database
Storing large files like PDFs, images, and documents as BLOBs in database tables works for moderate volumes, but becomes expensive and difficult to manage at scale. Oracle Cloud Infrastructure (OCI) Object Storage provides virtually unlimited, low-cost file storage that integrates well with APEX applications through REST APIs and the DBMS_CLOUD package.
Setting Up OCI Object Storage
In the OCI Console, create a Bucket in your compartment. Buckets are containers for objects (files). Choose a storage tier: Standard for frequently accessed files, Infrequent Access for files accessed less than once a month, or Archive for long-term retention. Create an API key for authentication and note your tenancy OCID, user OCID, and the key fingerprint.
Uploading Files From PL/SQL
Use DBMS_CLOUD.PUT_OBJECT (available in Autonomous Database) or APEX_WEB_SERVICE for standard Oracle databases:
-- Using DBMS_CLOUD (Autonomous Database)
BEGIN
DBMS_CLOUD.PUT_OBJECT(
credential_name => 'OCI_CRED',
object_uri => 'https://objectstorage.us-ashburn-1.oraclecloud.com'
|| '/n/mytenancy/b/app-documents/o/invoice_12345.pdf',
contents => l_pdf_blob
);
END;
-- Using APEX_WEB_SERVICE (any Oracle DB with ORDS)
DECLARE
l_response CLOB;
BEGIN
l_response := APEX_WEB_SERVICE.MAKE_REST_REQUEST(
p_url => 'https://objectstorage.us-ashburn-1.oraclecloud.com'
|| '/n/mytenancy/b/app-documents/o/invoice_12345.pdf',
p_http_method => 'PUT',
p_body_blob => l_pdf_blob,
p_credential_static_id => 'OCI_API_KEY'
);
END;
Generating Pre-Authenticated Requests for Download
Rather than routing file downloads through your APEX application (which loads the file into the database server’s memory), generate a Pre-Authenticated Request (PAR) URL that lets users download directly from Object Storage:
-- Create a time-limited download URL
BEGIN
DBMS_CLOUD.CREATE_PRESIGNED_URL(
credential_name => 'OCI_CRED',
object_uri => 'https://objectstorage.../o/invoice_12345.pdf',
expiry_time => SYSTIMESTAMP + INTERVAL '1' HOUR,
presigned_url => l_download_url
);
-- Redirect the user to l_download_url
END;
APEX Integration Pattern
Store file metadata (filename, size, upload date, object storage path) in a database table. Store the actual file content in OCI Object Storage. When a user uploads a file through APEX, your page process sends the BLOB to Object Storage and records the path in your metadata table. When they download, generate a PAR URL and redirect. This keeps your database lean while providing unlimited file storage capacity.