It seems kind of weird to do a blog post around a feature that’s fairly well documented, but this came up twice this week, so I figured I’d throw it out there.
Scenario: I want to post up a record to be inserted into a table. The record will consist of a couple of regular values, but also a file, which will be stored as a BLOB.
Ok, how does this happen?
Let’s start from the POST request perspective.
We’re going to send the ‘regular’ data via the header as parameters.
The file is going to go up in the BODY of the request.
What does ORDS do with this?
The secret sauce bits, which are discussed in the docs here, is that ORDS auto binds the data from the body to :body.
It’s only avail on a POST or PUT.
This makes doing our INSERT very easy.
declare image_id integer; begin insert into gallery (title,content_type,image) values (:title,:content_type,:body) returning id into image_id; :status := 201; :location := image_id; end;
The other two values are plucked off the request headers:
And that’s it, really.
So the request from POSTMAN goes up, and into my table goes the BLOB.
Step by Step Example
I go into MUCH more detail, and I share all the code for how to insert a ROW via REST API here. It covers all sorts of data, not just LOBs.
You can build this same scenario yourself – exact same code I used, it’s in our DOCS.