Skip to Main Content

ORDS, SODA & JSON in the Database

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!

Need help with storing image file from ORDS (:body) to Oracle ATP directory

BilalMar 26 2021

Hi All,
I am trying to store image files to the FILES directory of the Oracle ATP database version 19c running in Cloud.
I created an ORDS service endpoint with a POST handler that accepts the file_name and file_type as http_header. I attach the image data as a binary file to the request body in Postman to invoke the service.
The PLSQL code used in the POST handler is as follows:

DECLARE
l$output_file utl_file.file_type;
BEGIN
  IF (:file_name IS NOT NULL AND :file_type IS NOT NULL AND :body IS NOT NULL) THEN
    
    -- Storing file in database file system
    l$output_file := utl_file.fopen('FILES', :file_name, 'w');
    utl_file.put_raw(l$output_file, :body);
    utl_file.fflush(l$output_file);
    utl_file.fclose(l$output_file);        
                
    :status := 201; -- http status code
  END IF;
END;

When I call the service, I receive 201 status code but the image stored inside the files has 0 bytes. See the entry 3 frame_001174.PNG in the screenshot below:
image.pngAny idea of how this can be fixed?
I will appreciate your response.
Many Thanks and
Kind Regards,
Bilal

This post has been answered by cormaco on Mar 29 2021
Jump to Answer
Comments
Post Details
Added on Mar 26 2021
3 comments
270 views