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.

Looping through rest API

nusa-JavaNetOct 7 2024

Hi all,

I am using this stored procesure to send / upload a liste of files via REST API to another server defined by the variable l_url, which is developed with Java SpringBoot.

-- Looping
for i in 1..l_Files.count LOOP
	    
  	apex_web_service.g_request_headers.delete();
	apex_web_service.clear_request_cookies;
	apex_web_service.clear_request_headers;

	apex_json.initialize_clob_output;
	apex_json.open_object;
	apex_json.open_object('uploadPart');
	apex_json.write('parm1', pParm1);
	apex_json.write('parm2', pParm2);
	apex_json.close_object;
	apex_json.close_object;
	 
	l_body := apex_json.get_clob_output( p_free => true );
	    
	-- Get the details of each files
    SELECT f.blob_content ,f.name
    INTO l_fileBlob ,l_tmpFile
    FROM apex_application_temp_files f
    WHERE f.name = l_Files(i);

  	-- The format of l_tmpFile is 21470730095421212/toto.MSI, need to get rid of all strings up to '/'
	l_filename := substr(l_tmpFile ,instr(l_tmpFile, '/') + 1);
	
   	apex_debug.info ('==> uploading : |%s| |%s| |%s| |%s|' ,i ,l_tmpFile ,l_filename ,dbms_lob.getlength(l_fileBlob));
		    
	apex_web_service.APPEND_TO_MULTIPART (
                p_multipart    => lm_multipart,
                p_name         => 'uploadPart',
                p_content_type => 'application/json',
                p_body         => l_body );
				
	apex_web_service.APPEND_TO_MULTIPART (
                p_multipart    => lm_multipart,
                p_name         => 'attachment',
                p_filename     => l_filename,
                p_content_type => 'application/octet-stream',
                p_body_blob    => l_fileBlob );
		
   	l_blob := apex_web_service.make_rest_request_b(
          p_url         => l_url,
          p_http_method => 'POST',
		  p_body_blob   => apex_web_service.generate_request_body(lm_multipart)
	);
	
   	apex_debug.info ('==> g_status_code: %s', apex_web_service.g_status_code);
      
end loop;

If I send just 1 file, it works OK.

The problem is when I send 2 files ( file1.txt et file2.txt ). The first iteration, all variables ( lm_multipart, l_filename, and l_fileBlob ) are correctly setup and SpringBoot received correctly.
But on the second iteration, as shown below, despite all varibles are also correctly setup / displayed, SpringBoot still receives the previous values. As if the multipart is never updated ( still the values from the first iteration ).

What do I need to configure in order to call a webservice repeatedly ?

This post has been answered by Carsten Czarski-Oracle on Oct 7 2024
Jump to Answer
Comments
Post Details
Added on Oct 7 2024
4 comments
186 views