juan
How do I download files uploaded with Exfile?
Hi,
I am developing an application on phoenix framework v 1.3. I have managed to upload files with exfile. I still do not know how to download the files. Do any of you have a file upload and download function? It would be useful to reuse code.
Thank you !
Most Liked
juan
I will keep trying, thank you for your time.
juan
With the help of @dokuzbir the application downloads files. When they are downloaded, they are not readable.
Steps to get to this point:
-
create a test application
mix phx.new hello -
Edit the mix.
in application
: exfile,: exfile_imagemagick
in deps
{: exfile, "~> 0.3.6"},
{: exfile_imagemagick, "~> 0.1.2"}
- Generate the context
mix phx.gen.html Accounts User users img: string name: string \ username: string: unique
-
Add on the route
forward "/ attachments", Exfile.Router
get "/ download", DownloadController,: download -
Create controller
defmodule HelloWeb.DownloadController do
import Exfile.Ecto.CastContentType
import Exfile.Ecto.CastFilename
use HelloWeb, :controller
def download(conn, %{“file_path” => file_path}) do
conn
IO.inspect file_path
|> put_resp_header(“content-disposition”, “attachment; filename=“test-file.jpg””)
|> send_resp(200, file_path)
end
end -
Add in the template show.html
<% = link Download, to: download_path (@conn,: download, file_path: exfile_path (@ user.img))%>
Now I’m trying to make the downloaded files readable
kokolegorille
FYI, double quotes are modified inside blockquote, but not inside code ![]()
Here is code starting with ```elixir
"this is ok"
Here is a blockquote, and double quotes are modified…
“this is not ok”







