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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Sending form data to a third-party server (multiple image files not sending)

User_U63IMAug 30 2021 — edited Aug 30 2021

Good day, all. I've been playing around with the APEX web service API on sending requests to a third-party API server (oracle cloud VM). I successfully requested the endpoints provided by the API server, but the request sent by APEX web service API seems not to allow multiple image files. In the APEX page designer, I did set the File Browse to "Allow Multiple Files".

declare
   l_newline varchar2(50) := chr(13) || chr(10);
   lco_boundary constant varchar2(30) := 'gc0p4Jq0M2Yt08jU534c0p';

   l_request_body clob;
   l_request_body_length number;
   l_req clob;
begin
   l_request_body := l_newline
   || '--' || lco_boundary || l_newline
   || 'Content-Disposition: form-data; name="user_id"' || l_newline
   || l_newline
   || :P3_GENERATED_ID || '--' ;

   FOR l_file IN (
       SELECT
       FILENAME,
       MIME_TYPE,
       BLOB_CONTENT
       FROM
       APEX_APPLICATION_TEMP_FILES 
   ) LOOP
       l_request_body := l_request_body || l_newline
       || '--' || lco_boundary || l_newline
       || 'Content-Disposition: form-data; name="userFaces"; filename="' || l_file.FILENAME || '"' || l_newline
       || 'Content-Type: '|| l_file.MIME_TYPE || l_newline
       || 'Content-Transfer-Encoding: base64' || l_newline
       || l_newline
       || apex_web_service.blob2clobbase64(l_file.BLOB_CONTENT) || l_newline
       || '--' || lco_boundary || '--';
   END LOOP;

   l_request_body_length := dbms_lob.getlength(l_request_body);

   apex_web_service.g_request_headers(1).name := 'Content-Length';
   apex_web_service.g_request_headers(1).value := l_request_body_length;
   apex_web_service.g_request_headers(2).name := 'Content-Type';
   apex_web_service.g_request_headers(2).value := 'multipart/form-data; boundary="' || lco_boundary || '"';

   l_req := apex_web_service.make_rest_request(
        p_url => 'https://<third-party-API-server>',
       p_http_method => 'POST',
       p_body => l_request_body);

end;

For the API server, it's a simple API server build with Flask, and these are the code I used to receive the form data in the application.

user_id = request.form.get("user_id")
files = request.files.getlist("userFaces")

As for the input, sending one image in the request didn't produce any weird behaviour. But, once I tried to make a request with multiple images as form-data, the server only receive the first image.

Comments

Post Details

Added on Aug 30 2021
1 comment
655 views