This site is currently read-only as we are migrating to Oracle Forums for an improved community experience. You will not be able to initiate activity until January 31st, when you will be able to use this site as normal.

    Forum Stats

  • 3,890,899 Users
  • 2,269,649 Discussions
  • 7,916,821 Comments

Discussions

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

User_U63IM
User_U63IM Member Posts: 1 Green Ribbon
edited Aug 30, 2021 1:45PM in APEX Discussions

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.

Answers