Feedback wanted for API to support for multi file upload

61 views
Skip to first unread message

Johannes Hoppe

unread,
Aug 25, 2018, 3:05:42 PM8/25/18
to Django developers (Contributions to Django itself)
Hi there!

I do need some feedback on the best public API to implement multi file support to Django forms.

Context:

Up until now Django forms do not support multi file upload. You will need to write your own view to handle the files as described here:

Of course it is not too hard to implement actual multi file support as I have been showcasing here:

The question is now to best add support for multiple file uploads without wrecking backwards compatibility?

As Tim wisely mentioned, it might be confusing to add a `multiple` argument to the FileField while also having the 
attrs={'multiple': True}
still in the mix.

My suggestion would be to add the new keyword argument which enable the new behavior and keep the attr-thing as is.
I could add a warning if someone uses the "old" style. It is a bit suggestive though.

What do you think, mabe look at the documentation changes in the PR for more context.

Best
-Joe

Adam Johnson

unread,
Aug 26, 2018, 10:33:31 AM8/26/18
to django-d...@googlegroups.com
My suggestion would be to add the new keyword argument which enable the new behavior and keep the attr-thing as is.
I could add a warning if someone uses the "old" style. It is a bit suggestive though.

Whilst it's not the normal way of deprecating things in Django, I'm not against it. Would we ever block attrs={'multiple':True} though? Afaiu there would still be use cases for setting that attribute and doing custom multiple file handling. Maybe even a warning wouldn't be necessary.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/e71675d3-be96-4189-b0c1-038774626284%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Adam

Johannes Hoppe

unread,
Aug 27, 2018, 2:38:14 AM8/27/18
to Django developers (Contributions to Django itself)
Hi Adam!


On Sunday, August 26, 2018 at 4:33:31 PM UTC+2, Adam Johnson wrote:
My suggestion would be to add the new keyword argument which enable the new behavior and keep the attr-thing as is.
I could add a warning if someone uses the "old" style. It is a bit suggestive though.

Whilst it's not the normal way of deprecating things in Django, I'm not against it. Would we ever block attrs={'multiple':True} though? Afaiu there would still be use cases for setting that attribute and doing custom multiple file handling. Maybe even a warning wouldn't be necessary.
I am with you on that one. There is no need to prevent the other. Maybe it does boil down to a crisp sentence in the documentation that encourages users to use the new feature.
Thanks joe 

Brice Parent

unread,
Aug 27, 2018, 3:12:30 AM8/27/18
to django-d...@googlegroups.com

Hi Joe,

Just an idea:

Why not just use another keyword argument, like "files_number", "count", "max_files" (along maybe with a "min_files"), or something like, with a default of 1 (to match current behaviour with a single file), and an allowed value of 0 for infinite?

If you allow multiple files upload at once, chances are that there will be many use cases for limiting the number of uploads to a specific range/value.

Not sure about the form's implementation, though.

- Brice

Johannes Hoppe

unread,
Aug 27, 2018, 3:22:13 AM8/27/18
to django-d...@googlegroups.com
Hi Brice,

Interesting thought. I never looked at it from this perspective.

I did some research. There is no way to reflect a file limit a HTML form (without Javascript).
Furthermore there is no way to prevent people to send a request with more files, you could only limit the request body size (which is recommendable anyways). So if one would send more then the max file limit, would we respond with a 400 response?

Looking at all this I see too many question marks. I would want to keep this simple and keep the same pattern the HTML file input follows. That might just be more intuitive for users anyways.

Good thinking tho, brilliant.

Best
-joe

--
Johannes Hoppe

www.johanneshoppe.com

Want to chat? Let's get a coffee!
https://calendly.com/codingjoe/coffee

Lennéstr. 19
14469 Potsdam

USt-IdNr.: DE284754038
You received this message because you are subscribed to a topic in the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-developers/U9XNvd4Q2vY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-develop...@googlegroups.com.

To post to this group, send email to django-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
Reply all
Reply to author
Forward
0 new messages