juan

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

juan

I will keep trying, thank you for your time.

juan

juan

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

kokolegorille

kokolegorille

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”

Last Post!

juan

juan

Thank you!

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
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
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
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
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
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
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement