1. Overview

This document talks about how to push the blob uploaded by the end-user to Oracle Cloud Storage.

2. Technologies and Tools Used

The following technologies has been used to achieve pushing blob to cloud storage.

  • PLSQL

3. Use Case

Storing the blob content into the Oracle Table will increase the volume of the database. This leads to the challenge in maintaining the database. To overcome such scenario, instead of storing the blob content directly into the table, we can push the blob to cloud storage and we store the url to access the blob into the table for accessing the blob. This blog describes how we can achieve the same using the PLSQL.

4. Architecture 

Step 1:  Create a File browse item under a region in the target page.

Step 2: Create a button Upload to call the plsql process.

Step 3: Create a PLSQL process and place the below code,

/*replace url and api given in the code with your url and api key*/

DECLARE

    lv_cloudurl       VARCHAR2 (2000);

    lv_response       CLOB;

    lv_url_response   VARCHAR2 (2000);

    lv_blob_content   BLOB;

    lv_cont_url         VARCHAR2 (2000) := ‘https://xxxxyyyyy.com/xzz’; –Container_url

    lv_base_url         VARCHAR2 (2000) := ‘https://xxxxyyyyy.com/xyy’;–base url

    lv_body           CLOB;

BEGIN

    lv_body :=

           ‘{“bucket_name” :”enteryourbucketname”,”file_path”:”image/”,”file_name”:”‘

        || :P100_FILE_NAME

        || ‘”}’;

 

    /*intialize header variables*/

 

    apex_web_service.g_request_headers (1).name := ‘Content-Type’;

    apex_web_service.g_request_headers (1).VALUE := ‘application/json’;

    apex_web_service.g_request_headers (2).name := ‘x-api-key’;

    apex_web_service.g_request_headers (2).VALUE :=

        ‘xxxxxxxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyyyyyyy’;              –place your key

 

    /*raise a request*/

    lv_url_response :=

        apex_web_service.make_rest_request (p_url           => lv_base_url,

                                            p_http_method   => ‘POST’,

                                            p_body          => lv_body);

 

    /*get uploaded file*/

 

    SELECT BLOB_CONTENT

      INTO lv_blob_content

      FROM apex_application_temp_files

     WHERE NAME = :P100_uploadfile;

 

    /*push the blob*/

    lv_response :=

        apex_web_service.make_rest_request (

            p_url           => lv_url_response,

            p_http_method   => ‘PUT’,

            p_body_blob     => lv_blob_content);

/*Below code is to get the stored blob url*/

    /*configure header variables*/

    apex_web_service.g_request_headers (1).name := ‘Content-Type’;

    apex_web_service.g_request_headers (1).VALUE := ‘application/json’;

    apex_web_service.g_request_headers (2).name := ‘x-api-key’;

    apex_web_service.g_request_headers (2).VALUE :=

        ‘xxxxxxxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyyyyyyy’;              –your key

    /*get the stored image url*/

    lv_cloudurl :=

        apex_web_service.make_rest_request (p_url           => lv_cont_url,—container url

                                            p_http_method   => ‘POST’,

                                            p_body          => lv_body);

 

    /*store the url to access the uploaded file*/

    INSERT INTO blobreftb (FILE_NAME, URL)

         VALUES ( :P100_FILE_NAME, lv_cloudurl);

EXCEPTION

    WHEN OTHERS

    THEN

        apex_error.add_error (

            p_message            => ‘Error in accessing the cloud storage’,

            p_display_location   => apex_error.c_inline_in_notification);

END;

Step 3: Save the Changes and run the page.

 

Recent Posts

Start typing and press Enter to search