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
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 13 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
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.
vfsoraki
About “
[]” suffix, The specs are fairly simple, here.It is a server-side convention. HTTP specs see
a[]=1&a[]=2anda=1&b=2anda[a]=1&a[b]=2all as some key-value pairs. It’s the server-side who decides to represent first one as array, second one as simple values and third one as hash-maps or objects.You could easily write a server-side framework to parse
a_1=1&a_2=2into array, but since almost all languages use[]notion for arrays, it seemed natural to the first developers.OvermindDL1
???
That’s precisely what I’m doing?
MikeAndrianov
Hey! I would recommend you just to use direct uploading.
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.
OvermindDL1
Raw html for my php test, a
form_forfor my phoenix test, they weren’t quite equal… ^.^;Unsure, I first saw it in PHP a long LONG time ago…
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?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. ^.^OvermindDL1
I need to be able to fall back to no javascript and still have it fully work, requirements of my job. ^.^;
All local network, if there are network issues then there are bigger problems and this suddenly doesn’t matter. Uploading of the entire set is only about 40 megs as it is and this will happen rapidly on some days and then be pretty dead for weeks at a time.
Doesn’t matter one tiny iota here, gigabit network. ^.^
I don’t want to create a github issue for what seems to be a pure usability issue. This is the first time I’ve needed to upload files to a phoenix server so it’s outside of my realm of knowledge. It works fine in php and with python servers though and those were pretty trivial to get working (iterate a file list).
I would highly doubt this, it is part of the spec and they seem to follow the spec fairly well for most other things.
Hmm, I wonder how this would respond to me trying to upload a directory… testing…
Edge and Firefox both don’t allow me to upload a directory, only multiple explicit files.
I’ve tested in Chrome, Firefox, and Edge and all had no issues with the PHP test script for them.
Yep, PHP has the same thing, you need to have
[]at the end of the name for PHP’s built-in handlers to handle it.Well both PHP (built-in) and Python (flask) had no issues with them? In PHP you just iterate the file list (it’s an array) and in flask you just call
request.file.getlist("files[]"), it was all super simple (unlike phoenix/plug so far but I still assert it has to be me doing something wrong, at the very least in needs a doc fix though…).Eiji
If I remember it correctly then there needs to be some specification regarding content parsing - probably from
W3C, but I’m not sure about it. I saw really long specification forHTML/HTML5document parsing and as it’s related to it (as a part of<input/>specification) it should be described well or at least linked to 3rd-party specification page. It may be also described or linked on browser developer pages (likeMDN) in contents ofGeckoorWebKitspecifications. My last idea are issue trackers with tickets for adding support for it, so there should be a commit(s) which are encoding form to valid request body, so by knowing how it works somebody could write a parser.In short somebody would need to find up-to-date specification page and update
plugbody parser related code.