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







