ARCS Delete File Procedure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PROCEDURE delete_file | |
(p_base_url IN VARCHAR2, | |
p_file_name IN VARCHAR2, | |
p_file_path IN VARCHAR2) IS | |
l_payload_json CLOB; | |
l_response_clob CLOB; | |
l_complete_url VARCHAR2(500); | |
lc_interop_path CONSTANT VARCHAR2(100) := 'interop/rest/v3/files/delete'; | |
l_status NUMBER; | |
l_details VARCHAR2(1000); | |
BEGIN | |
-- Set the HTTP Headers for uploading a binary file. | |
apex_web_service.g_request_headers.DELETE; | |
apex_web_service.g_request_headers(1).NAME := 'Content-Type'; | |
apex_web_service.g_request_headers(1).VALUE := 'application/json'; | |
-- Build complete URL to REST API. | |
l_complete_url := p_base_url || lc_interop_path; | |
apex_debug.info('XX Delete API URL [%s]', l_complete_url); | |
-- Build JSON Payload | |
l_payload_json := '{' || | |
'"fileName": '|| apex_json.stringify(p_file_path||'/'||p_file_name)|| | |
'}'; | |
apex_debug.info('XX JSON Payload [%s]', l_payload_json); | |
-- Call the REST API to Delete the File. | |
l_response_clob := apex_web_service.make_rest_request | |
(p_url => l_complete_url, | |
p_http_method => 'POST', | |
p_transfer_timeout => 10, | |
p_body => l_payload_json, | |
p_credential_static_id => 'ARCS_BASIC_AUTH'); | |
apex_debug.info('XX HTTP Response [%s], Payload [%s]', apex_web_service.g_status_code, l_response_clob); | |
IF apex_web_service.g_status_code = 200 THEN | |
-- Check the status field in the JSON response. | |
apex_json.parse(l_response_clob); | |
l_status := apex_json.get_number(p_path => 'status'); | |
IF l_status <> 0 THEN | |
l_details := apex_json.get_varchar2(p_path => 'details'); | |
apex_debug.error('XX API Status [%s], Details [%s]', apex_json.get_number(p_path => 'status'), l_details); | |
raise_application_error(-20001, 'Failed to Delete File ['||l_details||']'); | |
END IF; | |
ELSE | |
apex_debug.error('XX HTTP Error [%s], Payload [%s]', apex_web_service.g_status_code, l_response_clob); | |
raise_application_error(-20002, 'Error from Delete File API ['||apex_web_service.g_status_code||']' || l_response_clob); | |
END IF; | |
END delete_file; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment