OvermindDL1
So I need users to upload a few hundred to a few thousand tiny image files, obviously doing that picture-by-picture would be extraordinarily painful, so using the multiple option of the standard file input element to allow selecting the entire directories contents.
Now, when doing <input type="file" id="images" name="images"> I get a %Plug.Upload{} structure just fine, however if I do <input type="file" id="images" name="images" multiple> then I get a binary that is the name of one of the listed files, so changing that to <input type="file" id="images" name="images[]" multiple> gets the params giving me a list of binaries of the file names, however these are not %Plug.Upload{} structures, so I don’t know anything beyond the filenames, like say the contents of the files.
I’ve found this past thread here that was useful enough to get me to add the [] part to the name, but don’t actually help me getting to the contents (and if you check the attached github issue they never seemed to handle it either):
Furthermore, using inotifywait on the entirety of the /tmp directory shows there is no file writing happening at all for a multiple file upload, yet single file uploads without the multiple attribute save and are deleted just fine.
The docs of Plug.Upload are not useful on this issue either.
The total size of the files are well well below the max file size (only a couple hundred kb while testing and just trying to get it working).
Considering this seems to be a pretty basic use-case I have to be screwing up pretty big somewhere, thus any assistance would be very welcome! ^.^;
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Marked As Solved- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
OvermindDL1
Ah hah! I am the idiot! To forever encode my missing bit into history and maybe help others later, don’t forget the
multipart: trueoption to the form call! I noticed it within seconds of opening the file when I got in today. Yesterday was a loooong day and I missed the obvious. ^.^Also Liked
gregvaughn
I can’t confirm either, but I know Rails uses it, and DHH is from the PHP community, so that’s my assumption of where it comes from.
peerreynders
More importantly - post the entire
formfragment when discussing problems withinputelements. On MDNenctype="multipart/form-data"kind of sticks out like a sore thumb - but I figured that you had that covered given you got the PHP version working.Aside: Does anybody have any information on the origin of the “
[]” name suffix convention for multiple files? It seems that the HTML specification doesn’t require it but it seems to be more of a server-side convention (PHP specifically). Or am I wrong about this?Eiji
Only for standard
HTTPupload. Is notWebSocketsstandard better for that? You can send multiple files at a time in their own small requests without sendingHTTPheaders, extra (every request) validation etc. It’s also better to for future changes like showing upload progress, chucking etc. Personally I don’t like also ideas of sending multiple files in one request. Application should work as long as it can. In your case if you would have a network problem in the middle of process then you would need to send again all of hundred or even few thousand files. Even if they are tiny it’s not good for user experience and it’s also not scalable solution. Remember that there are still people which do not have fast fiber internet.I believe that @josevalim should know best this problem as he is most active contributor to
plug. I think that you should create aGitHubissue for this problem inelixir-plug/plug. I did not looked at source code ofplug, but if I would guess then I think thatplugis trying to handlemultipleupload as same as normal upload which means that it hits an edge case offile uploadimplementation inplugwhere developers does not expect to parse request content ofmultiplefiles. Also I believe that Issue when uploading a file with multipart/form-data with Chrome but trying to upload a directory instead of a fileplugissue is really similar to your case (not properly handled request content standard). Again I recommend to create new issue with providing all data as in linked issue. Also if you would look on that issue then you would see that different browsers could send requests content in different format, so make sure to test them and give us information about it as in linked issue.Yeah, just found that @josevalim commented about it 2 years ago:
This means that you need to have multiple
file_inputwithnamewhich ends with[](because it showsPhoenixthat we want to save value of multiple inputs into one list).[]suffix should not change parsing parameters for only one field. Just instead ofvalueyou would have[value]and nothing more, so it’s useless for you.Last Post!
Jetmush
Nice functionality you got there OverMindDL1, Please help me on how i can structure my controller i’m new to elixir and i need your help on how the controller and the schema should look like should look like, the one which handles this post request. And please mention if there is a way of achieving this without using a library. Personally i’m using Arc for my image upload but its only able to send one image at at time. I don’t know where i’m going wrong.