Oracle OSB download DB BLOB file in browser

in osb •  6 years ago 

Requirement:

File Data present in tables as BLOB. A rest service should be exposed to download the file content from browser in Oracle Service Bus OSB.

Table structure

CREATE TABLE X

( XNO NUMBER, --id

COLUMN1 BLOB, --file

COLUMN2 TIMESTAMP (6),

COLUMN3 VARCHAR2(200 BYTE), --filename

COLUMN4 VARCHAR2(500 BYTE) --version

)

Example url : https://host:port/OrigDocFetchService/ProxyService?id=1&documentName=Overview1.pdf&version=1.0

How it is implemented::

The proxy first receives the request and identifies the content type based on the documentname passed in the query parameters.

Then it fetches the content from Database via DB Adapter. (Please read documentation on how to configure db adapter which links db via datasource in weblogic)

Once Document is fetched from DB then we have a helper function DataSource decode64ToStream(String) to help convert the base64 encoded value which OSB gives from DB to a stream which browser can act on.

Then the Content-Type and disposition tags Content-Disposition are set as below

Content-Type = $contentType example 'application/pdf;' for pdf or 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' for docx content

(Please refer https://technet.microsoft.com/en-us/library/ee309278(office.12).aspx)

Content-Disposition = concat("inline; filename=""",$inbound/ctx:transport/ctx:request/http:query-parameters/http:parameter[@name='documentName']/@value,"""")

example "inline: filename: "Overview1.pdf""

Once these headers are set and binary stream flowing back to browser as body then the browser will be in a position to download the content.

The full java helper functions and OSB project can be available at below github repository.

https://github.com/praveencasimir/DownloadBLOBSBProject

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Hi! I am a robot. I just upvoted you! I found similar content that readers might be interested in:
http://praveenarockiasamy.blogspot.com/

Congratulations @praveen.casimir! You have received a personal award!

1 Year on Steemit
Click on the badge to view your Board of Honor.

Do not miss the last post from @steemitboard:

SteemitBoard knock out by hardfork

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @praveen.casimir! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!