omin

omin

Multiple File Upload

Is it possible to create <input type="file" multiple> using <%= file_input f, :photo %>?

I couldn’t find anything in the Phoenix File Upload guide nor the Phoenix.HTML doc.

My very basic solution would be using Javascript make a button create multiple <input class=" id="app_photo" name="app[photo1]" type="file"> and increment the photo number as you add more photos. This seems more of a hack though.

Most Liked

omin

omin

(partly) Solved! https://github.com/elixir-lang/plug/issues/436#issuecomment-240870002Solved.

Thanks @sysashi. I didn’t understand what you were saying at first but you were right. I think I was blinded by what I was expecting to see from the library.

omin

omin

Adding multiple:true option did the trick!

However, Plug.Upload doesn’t seem to have an array of filenames. It only has filename: binary plug/lib/plug/upload.ex at main · elixir-plug/plug · GitHub.

If we had multiple file inputs and if the user selected photos for all of them, we would have multiple files in this directory. Plug will make sure all the filenames are unique.

So I guess I’ll have to access the system files to get the names?


Update.
I tried to print out the files in the director but I got this: could not list directory "/var/folders/tm/4nhcmhhx5sbcg1st3_kywz400000gn/T//plug-1471/multipart-498792-367218-1": not a directory

I created a github issue to further investigate: Plug.Upload returns incorrect path? · Issue #436 · elixir-plug/plug · GitHub

sysashi

sysashi

Note: This file is temporary, and Plug will remove it from the directory as the request completes. If we need to do anything with this file, we need to do it before then.

Do you process your files while request is still alive?
And I believe that multipart-498792-367218-1 is the name of a file not a directory.

Where Next?

Popular in Questions Top

Tee
can someone please explain to me how Enum.reduce works with maps
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
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
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
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
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
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
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
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
RisingFromAshes
I've read in another post that it may be possible with a router helper - but I couldn't find an appropriate one, and tbh, I'm still just ...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35953 110
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
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31107 143
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New

We're in Beta

About us Mission Statement