0

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.

3
  • What version of APEX and ORDS are you currently using?
    – EJ Egyed
    Commented Oct 24, 2022 at 20:00
  • @EJEgyed Its on Oracle cloud , APEX version 22.1.4 , ORDS version 22.3.0.r2781755
    – Octavarium
    Commented Oct 25, 2022 at 5:38
  • 1
    added the oracle-ords tag Commented Oct 25, 2022 at 6:10

1 Answer 1

2

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.

11
  • 1
    Thank you my service is working now. Working just like you said.
    – Octavarium
    Commented Oct 25, 2022 at 13:33
  • is it possible to have Content-Length in the header. I have some issues with pictures, for example image preview not working in Viber messages
    – Octavarium
    Commented Oct 26, 2022 at 5:34
  • yes, but then we're going to get more interesting. you're going to write a pl/sql block to get the LOB and print it, and then run another query to get the size of the LOB and then assign that to your header Commented Oct 26, 2022 at 12:49
  • @Octavarium I updated my answer to get you started on the response header you were asking about. Commented Oct 26, 2022 at 13:37
  • i used that procedure in my handler and changed source to PL/SQL , In postman when i call my link I see picture but in header still don't see content- length.
    – Octavarium
    Commented Oct 26, 2022 at 17:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.