create or replace FUNCTION func_get_oss_url(key VARCHAR2)
RETURN VARCHAR2
AS
    -- Call File Upload Service
    lv_method     VARCHAR2(30)  := 'POST';
    lc_req_body   CLOB;
    lv_url        VARCHAR(4000) := 'http://localhost:8000/get_download_url/';
    lc_res_body   CLOB;

    lj_object     JSON_OBJECT_T;
    lv_result     VARCHAR2(4000);
BEGIN
    IF key IS NULL THEN
        RETURN NULL;
    END IF;

    -- Call File Upload Service
    apex_web_service.g_request_headers(1).name := 'Content-Type';
    apex_web_service.g_request_headers(1).Value := 'application/json; charset=utf-8';

    lc_req_body := '{
                        "key": "' || key || '"
                    }';

    lc_res_body := APEX_WEB_SERVICE.make_rest_request(
        p_url         => lv_url,
        p_http_method => lv_method,
        p_body        => lc_req_body
    );

    -- Parse Service Result
    lj_object := JSON_OBJECT_T.parse(lc_res_body);
    lv_result := lj_object.get_string('result');
    lv_url := lj_object.get_string('download_url');

    IF lv_result = '0' THEN
        RETURN lv_url;
    ELSE
        RETURN null;
    END IF;

EXCEPTION
    WHEN OTHERS THEN
        RETURN NULL;

END func_get_oss_url;
/