oracle-databaseoracle-apexoracle-ords

RESTful service - file name and extension in URL


I created RESTful service in Oracle apex to get BLOB - images from one table. Everything goes fine and when I browse my link I get a picture in my browser.

My link goes something like:

https://rfmmitfabizwp2c-bcloud.adb.eu/test123/image Problem is API service on another side needs this link to be configured in format with filename and extension like:

https://rfmmitfabizwp2c-bcloud.adb.eu/test123/nameofmyimage.jpg

Is there a way to construct a link like this in Oracle Apex RESTful service. Is there any other way to construct a link like this to retrieve my blob image column from a table in database.


Solution

  • Your REST API template just needs to be

    test123/:file_name
    

    And then in your GET handler code, the SQL needs to have a WHERE clause that says, OK here's the file I actually want. This assumes you're storing the file name along with the file in your table.

    Here's an example -

    enter image description here

    More details here.

    The handler code -

    ORDS.DEFINE_HANDLER(
          p_module_name    => '101',
          p_pattern        => 'files/:file_name',
          p_method         => 'GET',
          p_source_type    => 'resource/lob',
          p_items_per_page => 25,
          p_mimes_allowed  => NULL,
          p_comments       => NULL,
          p_source         => 
    'select mime_type, the_file
    from blobs
    where FILE_NAME = :file_name');
    

    Obviously the SQL needs updated to match your table & column definitions.

    Disclaimer: I work for Oracle and am the product manager for ORDS.