For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!
Hi,
Does soneone know if there is a way to check if a BLOB image is either jpg, png, or gif?
Thanks and Regards
Laury wrote:Hi,Does soneone know if there is a way to check if a BLOB image is either jpg, png, or gif?
Laury wrote:
yes, it is possible & MS Windows does it incessantly every second.
First you start with enumerating file content differences between the different image types.
Compare the "magic numbers".
https://en.wikipedia.org/wiki/List_of_file_signatures
Normally, I'd say "use Oracle MultiMedia data type ORD_IMAGE" -- but - that was deprecated/no longer supported.
MK
Hi, and inside a PL/SQL block?
With great difficultly I suspect.
Why don't you just store the image type in a separate column when inserting the blob?
Laury wrote:Hi, and inside a PL/SQL block?
Use the following:
Normally, you want to store the following data inside the table
I'm assuming that you need to find out what the MIMEType is.
@Cookiemonster76:
This is OK if know the image type before to store it in a table.
How can I get that type at the time I download that image?
@Mike:
Nice tips, but with these functions, how can I get the image type (jpeg, bmp,...)?
Kind Regards
Here is a basic example:
Extract the first 3 bytes from the BLOB and compare it with 'FFD8FF'. According to the list of signatures in the link that Mike posted, this is then a JPG:
select case when dbms_lob.substr(product_image,3,1) = hextoraw('FFD8FF') then 'JPG' end as image_type from demo_product_info
You can extend this case expression for any other file type.
Laury wrote:@Mike:Nice tips, but with these functions, how can I get the image type (jpeg, bmp,...)?Kind Regards
Read the section "Magic Number in Files" to understand what you need to do. (ie compare first n bytes to something)
https://en.wikipedia.org/wiki/Magic_number_(programming)
The "List of file signatures" has the something you need to compare to.
I leave it as an exercise to the student to create a function that discovers what the MIME Type is for a file based on a "short list" of "known image/* MIMETypes".
You may need to use one or more of the following: (the student should read the documentation on such functions)
Final hint: IN OUT NOCOPY
Beyond that, you should post up "what you have tried".
My $0.02
Hi Mike,
I have seen your post, I will come back to it as soon as I can.
Thanks for all the answers.
You asked: Beyond that, you should post up "what you have tried".
At that stagem I had tried nothing. Just when dowmloading an image from the filesystem to the database using a PL/SQL procedure, I wanted to check what kind of image it was: PNG, JPG,...
So, in fact to be able to identify a mimetype.
I know it is possble when loading it through APEX...
You posted very interesting links, and I feel I am like a student :-)
@Cormaco:
Yes, you posted a quick solution, that is actually good enough for my needs.
@John:
Yes, that's possible... but you didn't explained how it can be catched by PL/SQL up.