POST Up a BLOB to an Oracle Table via REST

thatjeffsmith ORDS 0 Comments

Tell Others About This Story:

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.

It just so happens my table has columns for Content-Type and a description.

The file is going to go up in the BODY of the request.

BINARY.

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.

I can plug the BLOB value right in there by just referencing the data via ‘:body”

The other two values are plucked off the request headers:

bingo, bango, bongo!

And that’s it, really.

So the request from POSTMAN goes up, and into my table goes the BLOB.

And that’s the REST of the story.

Step by Step Example

You can build this same scenario yourself – exact same code I used, it’s in our DOCS.

Tell Others About This Story:

Leave a Reply

Your email address will not be published. Required fields are marked *