Reputation: 145
I am looking for a example that passes a json file in the request body to the apex_web_service.make_rest_request Can someone please point me to an example ?
Thanks, RD
Upvotes: 0
Views: 2576
Reputation: 716
I see two ways to send files via apex_web_service.make_rest_request. In my examples I used an image file blob retrieved from table SAMPLE_TABLE column BLOB_LOGO.
cache the file blob type directly from the query into a blob object and send it via p_body_blob parameter
DECLARE
obj_sample SAMPLE_TABLE%ROWTYPE;
file_blob blob;
l_response clob;
BEGIN
-- query
select * INTO obj_sample
from SAMPLE_TABLE where ID = 123;
-- file as blob
file_blob := obj_sample.BLOB_LOGO;
l_response := apex_web_service.make_rest_request(
p_url => 'url/to/api/',
p_http_method => 'POST',
p_body_blob => file_blob,
p_proxy_override => 'url/to/proxy'
);
dbms_output.put_line(l_response);
END;
first convert the file blob datatype into a base64 clob object and send it as json body (clob) via p_body parameter
DECLARE
obj_sample SAMPLE_TABLE%ROWTYPE;
json_sample clob;
file_clob clob;
l_response clob;
BEGIN
-- query
select * INTO obj_sample
from SAMPLE_TABLE where ID = 123;
-- file as clob
file_clob := apex_web_service.blob2clobbase64(obj_sample.BLOB_LOGO);
json_sample := json_object(
'SAMPLE_LOGO' value img_clob
);
apex_web_service.g_request_headers(1).name := 'Content-Type';
apex_web_service.g_request_headers(1).value := 'application/json';
l_response := apex_web_service.make_rest_request(
p_url => 'url/to/api/',
p_http_method => 'POST',
p_body => json_sample,
p_proxy_override => 'url/to/proxy'
);
dbms_output.put_line(l_response);
END;
Upvotes: 2