Oracle APEX Web服务p_body_blob

g6ll5ycj  于 2023-10-16  发布在  Oracle
关注(0)|答案(1)|浏览(128)

我正在寻找一个例子,将请求体中的JSON文件传递给apex_web_service.make_rest_request有人能给我一个例子吗?
谢谢RD

ujv3wf0j

ujv3wf0j1#

我看到通过apex_web_service.make_rest_request发送文件的两种方法。在我的示例中,我使用了从表SAMPLE_TABLEBLOB_TABLE中检索的图像文件blob。

选项1:

直接从查询中将文件blob类型缓存到blob对象中,并通过p_body_blob参数发送

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;

选项二:

首先将文件blob数据类型转换为base64 clob对象,并通过p_body参数将其作为json body(clob)发送

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;

docs

相关问题