Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Sailesh.

Asked: April 11, 2017 - 10:50 am UTC

Last updated: October 02, 2025 - 1:36 am UTC

Version: 11

Viewed 10K+ times! This question is

You Asked

Hello

Is there any method to get the MIME type of BLOB data file using plsql?

Ex for PDF - application/pdf
for xlsm - application/octet-stream etc

For reference you can take fnd_lobs table in Oracle Applications.

and Connor said...

A blob doesn't *have* a mime type - its just binary data.

So unless you have *stored* the content type, or can derive it (eg by file name extension if you saved the filename as well), then you might be out of luck.

If you have the file name, you could use something like the list at

https://cs.chromium.org/chromium/src/net/base/mime_util.cc?l=201

to derive a mime type.

Rating

  (5 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Thanks but need MIME type from extension

Sailesh Arya, April 11, 2017 - 12:07 pm UTC

Thanks for the response.

Is there any api or function in plsql to get the mime type by taking the extension?
Please check.
Connor McDonald
April 12, 2017 - 5:30 am UTC

We can write one pretty easily

MIME_TYPE

No built-in API, I think...

J. Laurindo Chiappa, April 11, 2017 - 1:55 pm UTC

If I understood your needs correctly, you have inside the BLOB the FULL binary stream coming from a binary file, but NO INFORMATION about the original file extension, AND you want/need to discover the original file type only with this info, right ?
If so, let´s wait for the other answers but imho there is no built-in in RDBMS Oracle for this use, you will need to write some code to get the file signature (aka the 'magic number') to obtain that information, see https://en.wikipedia.org/wiki/List_of_file_signatures for a list of the most common ones....

Regards,

J. Laurindo Chiappa
Connor McDonald
April 12, 2017 - 5:17 am UTC

Agreed.

Oracle Multimedia

John Keymer, July 30, 2018 - 8:47 am UTC

Connor McDonald
August 01, 2018 - 12:36 pm UTC

Thanks for the info

Mime Type is inside the binary stream

Christo Kutrovsky, November 08, 2021 - 4:04 pm UTC

The mime type is more than an etention of the file, it can also be deduced by looking at the binary stream.

The unix 'file' command extracts the mime type based on the binary stream. It uses reference data from /etc/magic or /usr/share/magic and analyzes the contents of the file provided.

So a BLOB can absolutely have a "mime type" and it can be extracted by loading the metadata into the database and "analysing" the file.

This was done by Scott Stephens - link here with full code - https://www.techrepublic.com/article/oracle-tip-put-some-magic-into-your-database/

Note that the blog is from 2004.

The utility "PL/SQL Developper" from Allroundautomations (not to be confused by "SQL Developper" by Oracle) is looking at the BLOB value content and extracting the mime type, then suggests to open the correct application to "load" the file into.
Connor McDonald
November 09, 2021 - 3:59 am UTC

nice info

Mimetype on Securefile LOBs?

Kim Berg Hansen, October 01, 2025 - 9:08 am UTC

Connor said: "A blob doesn't *have* a mime type - its just binary data."

But DBMS_LOB package has SETCONTENTTYPE and GETCONTENTTYPE that works with Securefile LOBs.
Apparently Securefile LOBs can have some metadata?

That's not detecting mime type - but it could be a way to store mime type on a LOB, right?

-

(
As an aside, I thought this was used by SQL Developer for VS Code, because I tried this query:

select apex_barcode.get_qrcode_png(p_value=>'https://kibeha.dk',p_scale=>2) as qr_blob from dual;


And then in the output grid I right-click, go to Single Record View and click the three dots, which brings up details about the blob, where it states that the mime type is Image/PNG.

I thought that probably apex_barcode was using SETCONTENTTYPE, so VS Code was showing the result of GETCONTENTTYPE, but then I tried:

select dbms_lob.getcontenttype(apex_barcode.get_qrcode_png(p_value=>'https://kibeha.dk',p_scale=>2)) as qr_blob_type from dual;


And that gives error:

ORA-43856: Unsupported LOB type for SECUREFILE LOB operation
ORA-06512: at "SYS.DBMS_LOB", line 2127


So I guess that means that the SQL Developer VS Code extension probably utilizes some way of detecting mime type from the content, as apparently it cannot use GETCONTENTTYPE.
)

Cheerio
/Kim
Connor McDonald
October 02, 2025 - 1:36 am UTC

Agreed, but this is just putting additional data into the binary data that is the "blob".

Fundamentally it is always going to come down to how a calling client can infer/utilise this information, and as you've seen, there's no guarantee that any client is going to "know" to go and get it

More to Explore

CLOB/BLOB/etc

Complete documentation on Securefiles and Large Objects here