Hasimbola

Hasimbola

Store generated file inside created path

Hello , I have this code

def get_image do

{:ok, query} = Repo.query("SELECT photolink FROM produits")

for c <- query.rows do

  {:ok, photo} = Enum.fetch(c, 0)

  File.write("/tmp/#{photo}", photo, [:binary])

end

end

I want to store the file generated from File.write inside my project such as inside “/priv/uploads/file_name”
I am able to store the file inside /tmp but I have problem when I try to store the file inside another path

Please, can someone help me, thanks a lot

Thanks! :smiley:

Marked As Solved

egze

egze

"/priv/uploads/#{photo}" is an absolute path and doesn’t exist on your hard drive.

Look at this thread: Accessing the priv folder from Mix release - #2 by NobbZ

What you need is something like this:

"#{List.to_string(:code.priv_dir(:your_app_name))}/uploads/#{photo}"

or use a relative path.

Also Liked

LostKobrakai

LostKobrakai

This can be done simpler:
Application.app_dir(:your_app_name, Path.join("priv/uploads", photo))

NobbZ

NobbZ

In general you do not want to write to priv! You should consider it as a read only artifact store.

If you need to write to a persistent location, you should manage it aside to your application, and backup it seperately.

In general the priv folder is part of your release, if you really change its content, you invalidate the integrity of your release.

Files are stored in a separete section of your filesystem or in an S3 bucket or whatever file storage backend you use, and as such has to be considered state of your application similar to your PostgreSQL database.

LostKobrakai

LostKobrakai

What is the problem?

Hasimbola

Hasimbola

The program doesn’t found the path
I want to change

File.write(“/tmp/#{photo}”, photo, [:binary])

to something like this :

File.write(“/priv/uploads/#{photo}”, photo, [:binary])

but the path is not found , this return :

[{:error, :enoent}]

LostKobrakai

LostKobrakai

Are you sure parent folders of that path exist?

Where Next?

Popular in Questions Top

Tee
can someone please explain to me how Enum.reduce works with maps
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
logicmason
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
William
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
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
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
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...
273 38985 115
New

We're in Beta

About us Mission Statement