kodepett
Convert blob to file
I have an oracle database that stores documents (docx, jpg, pdf, png etc) in binary format(BLOB). I need to read the BLOB and convert it to a file with the appropriate format. How can I read and inspect the blob in Elixir to know the file format and convert it to the appropriate file.
First Post!
benwilson512
Does the database not store information about what kind of file it is? Arbitrary file type identification is quite tricky…
Most Liked
OvermindDL1
If it really is only a limited set of things, it wouldn’t be hard to build a simple cond test to detect the type it is from certain mandated markers within (a binary prefix on most of them), then you could fall back to a file_type test for more fuzzy/unknown things if there is any such things left in the DB.
NobbZ
What do you need the file type for?
Usually you can just write the blob to a temporary location, or stream it out to the client without delay or write to disk.
If though you are on linux and really need to know the MIME-type for whatever reasons, you can write the blob to disk and use file_info package to get the MIME-type. Be aware that this uses the file executable and shells out to your operating system. Returned info might be innacurate but as you only have restricted set of possible filetypes it might be accurate “enough”…
dimitarvp
Yep, you don’t have much hope beyond the file tool which can identify quite a lot of file types for you. Try it.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









