Reputation: 119
I am storing images as BLOB type in my DB, however I want to restrict it to only svg types, I know i cannot get the image name or anything from a blob but I assume I can get the format of the image at least, would like to know how to achieve this with oracle SQL.
Upvotes: 0
Views: 905
Reputation: 231661
As far as Oracle is concerned, a blob
is just a bunch of bytes. It has no idea whether it's an image or a document or a video so it has no idea what format anything might be. In theory, you could look up the specification of the SVG file format and write some code to try to recognize the file. How complicated this will be will depend rather heavily on how accurate you want to be in recognizing the file.
It appears that the SVG document format is an XML document that contains a number of svg
elements so you could do something like convert the blob
to a XML clob
and run an XPath expression on that looking for svg
elements. That wouldn't guarantee that you were correct-- I can create an XML document that has svg
elements that isn't an SVG file but it's probably close enough. Alternately, or in addition, you could look at the XML namespaces in the document to see if the svg
element is referencing a W3C SVG file format URL (i.e. xmlns:svg="http://www.w3.org/2000/svg").
Practically, though, if you care about the format of a blob
column, it generally makes far more sense to store metadata information in additional columns. Whatever is loading the data into the blob
column almost certainly has the ability to populate additional columns like file_name
, extension
, mime_type
, etc. so that you know what the column contains. You can then rely on those metadata columns rather than trying to parse out the contents of the file.
Upvotes: 1