Overview

Object Storage unit is a high-performance storage platform. It is ideal for storing an unlimited amount of unstructured data.The files can be uploaded and downloaded using object storage unit in oracle apex cloud.

Technologies and Tools Used

The following technology has been used to achieve the expected output.

  • Oracle Apex Cloud

Use Case

In oracle apex, To store and download the data user can use the different methods.The object storage unit is the one of the method which can be used in the cloud environment.Using the Object Storage unit you can store and retrieve the data. For the attachment upload and download here we are going to use the Object Storage unit.

This document explains how to use the Object Storage unit in the oracle apex cloud.

Architecture

The following steps will explain how to create and use the upload option.

Step 1:

Create item as type File browse.

Step 2:

Create a button named Upload and action as Submit Page.

Step 3:

Create the Upload process and set the server-side condition as when the button is pressed for Upload.

Step 4:

For the upload process using the below code,

DECLARE

  l_request_url    VARCHAR2(32767);

  l_content_length NUMBER;  l_response CLOB;

  upload_failed_exception EXCEPTION;

  l_request_object BLOB;

  l_request_filename VARCHAR2(500);

  l_selected apex_application_global.vc_arr2;

BEGIN

  l_selected   := apex_util.string_to_table (:P3_FILES, ‘:’);

  IF :P3_FILES IS NOT NULL THEN

FOR i IN 1 .. l_selected.COUNT    LOOP

      BEGIN

        SELECT blob_content, filename

        INTO l_request_object, l_request_filename

        FROM apex_application_temp_files

        WHERE name     = l_selected (i);

        l_request_url := :G_BASE_URL||’/b/’||abc-ocams-tst-be-atpd-bucket01’||’/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 => ‘OCI_OBJECTSTORAGE_AUTH’ );

      END;

    END LOOP;

  END IF;

END;

 

In the above code, we can give the below code instead of :G_BASE_URL or we can set the value as per the screenshot.

https://objectstorage.eu-amsterdam-1.oraclecloud.com/n/xxxxxxx

The OCI_OBJECTSTORAGE_AUTH in the above code will be available as per the below screenshot.

Using the above steps we can upload the data into the object storage unit.

Note: While uploading maintains the data in local tables like a file name. This can be used in the download.

The following steps will explain how to create and use the download option.

Step 1:

Create the report using the local table where download details are maintained.

Step 2:

Create a link column for download. Once we click the download column. this will redirect to another page. While redirecting pass the file name.

Step 3:

Create the hidden item as P4_OBJECT_NAME and download process in the page pre-rendering before the header.

 

Use the below code in the download process.

declare

  l_request_url varchar2(32767);

  l_content_type varchar2(32767);

  l_content_length varchar2(32767);

  l_response blob;

  download_failed_exception exception;

begin

  l_request_url := :G_BASE_URL||’/b/’ 

    ||’abc-ocams-tst-be-atpd-bucket01’|| ‘/o/’ 

    || apex_util.url_encode(:P4_OBJECT_NAME);

  l_response := apex_web_service.make_rest_request_b(

    p_url => l_request_url

    , p_http_method => ‘GET’

    , p_credential_static_id => ‘OCI_OBJECTSTORAGE_AUTH’

  );

  if apex_web_service.g_status_code != 200 then

    raise download_failed_exception;

  end if;

  for i in 1..apex_web_service.g_headers.count  loop

    if apex_web_service.g_headers(i).name = 

      ‘Content-Length’ 

    then

      l_content_length := 

        apex_web_service.g_headers(i).value;

    end if;

    if apex_web_service.g_headers(i).name = 

      ‘Content-Type’

    then

      l_content_type :=

        apex_web_service.g_headers(i).value;

    end if;

  end loop;

  sys.htp.init;

  if l_content_type is not null then

    sys.owa_util.mime_header(trim(l_content_type), false);

  end if;

  sys.htp.p(‘Content-length: ‘ || l_content_length);

  sys.htp.p(‘Content-Disposition: attachment; filename=”‘

    || :P4_OBJECT_NAME || ‘”‘ );

  sys.htp.p(‘Cache-Control: max-age=3600’); — if desired

  sys.owa_util.http_header_close;

  sys.wpg_docload.download_file(l_response);

 apex_application.stop_apex_engine;

end;

Using the above steps we can download the files.

Conclusion

In this document, We have seen how to upload and download files using an object storage unit in oracle apex cloud. In the previous, we have seen how to integrate the Object storage unit in the oracle apex Cloud.

How to Integrate Object Storage Unit in Oracle Apex Cloud

 

Recent Posts

Start typing and press Enter to search