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?

Last Post!

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.

Where Next?

Popular in Questions Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs &amp; Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 130579 1222
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement