How do I download files uploaded with Exfile?

i learnt ex_file :smile:. Looks like exfile_path doesnt take @conn use that. You should learn how to debug a elixir app.

<%= link “Download”, to: download_path(@conn, :download, file_path: exfile_path(@user.img)) %>

Great, thanks for your help. It still generates errors

== Compilation error in file lib/hello_web/views/user_view.ex ==
** (SyntaxError) lib/hello_web/templates/user/show.html.eex:7: unexpected token: ““” (column 7, codepoint U+201C)
(eex) lib/eex/compiler.ex:45: EEx.Compiler.generate_buffer/4
(phoenix) lib/phoenix/template.ex:378: Phoenix.Template.compile/2
(phoenix) lib/phoenix/template.ex:186: anonymous fn/3 in Phoenix.Template.“MACRO-before_compile”/2
(elixir) lib/enum.ex:1899: Enum.“-reduce/3-lists^foldl/2-0-”/3
(phoenix) expanding macro: Phoenix.Template.before_compile/1
lib/hello_web/views/user_view.ex:1: HelloWeb.UserView (module)
(elixir) lib/kernel/parallel_compiler.ex:198: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/6

again what is output of that

<%= exfile_path(@user.img) %>

It works, again it shows the text

/attachments/gwrkO8vdfVYJN8tK_hHtnL2yBVPnGhl4PjJRNOd_YDs=/cache/8a0cf98bf70e488e2d3ced494f5858be18f8ee728176b686fbb6b678e8f2/file

you should learn more elixir and disable encrypt. These codes should work. Your path looks right

I will keep trying, thank you for your time.

1 Like

last thing try that

<%= link “Download”, to: download_path(@conn, :download, file_path: "#{exfile_path(@user.img)}") %>

It produced error.

== Compilation error in file lib/hello_web/views/user_view.ex ==
** (SyntaxError) lib/hello_web/templates/user/show.html.eex:7: unexpected token: "“" (column 7, codepoint U+201C)
    (eex) lib/eex/compiler.ex:45: EEx.Compiler.generate_buffer/4
    (phoenix) lib/phoenix/template.ex:378: Phoenix.Template.compile/2
    (phoenix) lib/phoenix/template.ex:186: anonymous fn/3 in Phoenix.Template."MACRO-__before_compile__"/2
    (elixir) lib/enum.ex:1899: Enum."-reduce/3-lists^foldl/2-0-"/3
    (phoenix) expanding macro: Phoenix.Template.__before_compile__/1
    lib/hello_web/views/user_view.ex:1: HelloWeb.UserView (module)
    (elixir) lib/kernel/parallel_compiler.ex:198: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/6

i didnt understand what is that error. But doesnt look like about link. Error at line 7 in your show.html.eex

is the one we are adding

Downlaod should be yellor instead of green. Manually change double quotes yourself. Looks like forum changes double quotes

Thank you very much, this way it worked <%= link Download, to: download_path(@conn, :download, file_path: exfile_path(@user.img)) %>

Now I’m going to try to take the url dynamically in the controller

With the help of @dokuzbir the application downloads files. When they are downloaded, they are not readable.

Steps to get to this point:

  1. create a test application
    mix phx.new hello

  2. Edit the mix.

in application
: exfile,: exfile_imagemagick
in deps
{: exfile, "~> 0.3.6"},
{: exfile_imagemagick, "~> 0.1.2"}

  1. Generate the context

mix phx.gen.html Accounts User users img: string name: string \ username: string: unique

  1. Add on the route
    forward "/ attachments", Exfile.Router
    get "/ download", DownloadController,: download

  2. 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

  3. 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

1 Like

FYI, double quotes are modified inside blockquote, but not inside code :slight_smile:

Here is code starting with ```elixir

"this is ok"

Here is a blockquote, and double quotes are modified…

“this is not ok”

1 Like

Thank you!