Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

send large files in base64

Hello, I must use an api for electronic signatures and the idea is to send the documents through an external api, the problem is that I want to send it in base 64, but if the file is very large the limitations of varchar2 prevent me from doing so, any idea how I can solve it? I am using database version 23, this is my code

procedure pa_uplo_docu_byte(i_docu in clob, o_docu_id out varchar2) as

l_http_req UTL_HTTP.req;
l_http_resp UTL_HTTP.resp;
l_url VARCHAR2(4000) := 'https://dataflow-hml.code100.com.py/api/uploads/bytes';
l_payload CLOB;
l_payload_v VARCHAR2(32767);
l_response CLOB;
l_buffer VARCHAR2(32767);
l_json JSON_OBJECT_T;
l_id VARCHAR2(100);

l_json_data JSON_OBJECT_T;
l_json_clob CLOB;
BEGIN

-- Crear JSON en formato de objeto
l_json_data := JSON_OBJECT_T();
l_json_data.PUT('bytes', i_docu);

-- Convertir JSON a CLOB
l_json_clob := l_json_data.TO_CLOB();

-- Crear la solicitud HTTP
l_http_req := UTL_HTTP.begin_request(l_url, 'POST', 'HTTP/1.1');

-- Configurar los headers correctamente
UTL_HTTP.set_header(l_http_req, 'Content-Type', 'application/json');
UTL_HTTP.set_header(l_http_req, 'Accept', 'application/json'); -- Asegurar que devuelva JSON
UTL_HTTP.set_header(l_http_req, 'X-Api-Key', g_api_key);
UTL_HTTP.set_header(l_http_req,
'Content-Length',
l_json_clob);

-- Enviar el JSON en el cuerpo de la solicitud
UTL_HTTP.write_text(l_http_req, l_payload_v);

-- Obtener la respuesta
l_http_resp := UTL_HTTP.get_response(l_http_req);

-- Leer la respuesta de la API
LOOP
BEGIN
UTL_HTTP.read_text(l_http_resp, l_buffer);
DBMS_OUTPUT.PUT_LINE('l_buffer: ' || l_buffer);
l_response := l_response || l_buffer;
EXCEPTION
WHEN UTL_HTTP.end_of_body THEN
EXIT;
END;
END LOOP;

-- Cerrar la conexión HTTP
UTL_HTTP.end_response(l_http_resp);

-- Procesar el JSON de la respuesta
l_json := JSON_OBJECT_T.PARSE(l_response);
l_id := l_json.get_string('id'); -- Capturar el ID de la respuesta JSON
o_docu_id := l_id;
-- Mostrar el ID capturado
DBMS_OUTPUT.PUT_LINE('ID: ' || l_id);

EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Error: ' || SQLERRM);

END;

Comments
Post Details
Added on Feb 20 2025
1 comment
145 views