kodepett

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

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Does the database not store information about what kind of file it is? Arbitrary file type identification is quite tricky…

Most Liked

OvermindDL1

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

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

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.

Where Next?

Popular in Questions Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42716 114
New

We're in Beta

About us Mission Statement