Skip to main content

Command Palette

Search for a command to run...

Oracle APEX 20.2 and multipart/form-data

Updated
1 min read
Oracle APEX 20.2 and multipart/form-data
L

Oracle APEX Developer (Insum) from Paris Contributor of Flows for APEX Passionate about APEX and web development.

Before APEX 20.2, APEX_WEB_SERVICE package didn’t support multipart/form-data. If like me, you had to reach a web service which accept only this type of request body, you had to use the UTL_HTTP package and create the body by yourself. Nick Buytaert made a good post about it on his blog post (which helped me a lot).

But thanks to the APEX Team, the APEX_WEB_SERVICE package in release 20.2 introduce the support of multipart/form-data. The creation of this type of body have never been so simple.

declare
    l_multipart apex_web_service.t_multipart_parts;
    l_blob blob;
    l_body blob;
begin
    select blob_column 
    into l_blob
    from my_file_table
    where id = 1;

    apex_web_service.append_to_multipart(
        p_multipart    => l_multipart,
        p_name         => 'file',
        p_content_type => 'application/octet-stream',
        p_body_blob    => l_blob
    );

    l_body := apex_web_service.generate_request_body(
        p_multipart => l_multipart
    );

    l_response := apex_web_service.make_rest_request(
        p_url => 'https://...',
        p_http_method => 'POST',
        p_body_blob => l_body
    );
end;

The body sent with a simple text file is:

--A8BEA21E96C5B912
Content-Disposition: form-data; name="file"
Content-Type: application/octet-stream

This is a simple text file.
--A8BEA21E96C5B912--
E
Enock Oloo7mo ago

HI, i need your help . how do you pass both text payload + blob attachment...thanks.

S
Shruthi4y ago

can we send blob and text multipart content together using apex append to multipart?

                    || 'Content-Disposition: form-data; name="version"'
 || newline|| 1.0 
                      || 'Content-Disposition: form-data; name="maven2.asset1";'
                   || v_file
L

Yes, you have to call the procedure twice. Use the second signature that accepts a clob instead of a blob for the text.

More from this blog

Oracle APEX tips and tricks - Louis Moreaux

32 posts