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

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
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
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
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
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54996 245
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
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New

We're in Beta

About us Mission Statement