This multiple file upload view is working except when I exceed the settings.DATA_UPLOAD_MAX_NUMBER_FILES
value, currently at the default of 100. I understand I can set this to None and it would work but that would give up some DoS attack protection. Django throws django.core.exceptions.TooManyFilesSent
exception and returns a 500 error to the user. I would prefer to issue something more informative but none of the below view appears in the traceback, so try/except can’t be the way to handle it. What is?
class FileFieldFormView(LoginRequiredMixin, FormView):
form_class = FileFieldForm
template_name = "ingest/upload.html"
success_url = '/ingest/receiver/'
enctype = "multipart/form-data"
def form_valid(self, form):
files = form.cleaned_data["file_field"]
receiver = form.cleaned_data['receiver']
dir = os.path.join(settings.MEDIA_ROOT, PurePath(receiver.staging))
for f in files:
with default_storage.open(os.path.join(dir, f.name), 'wb') as staging_file:
for chunk in f.chunks():
staging_file.write(chunk)
return super().form_valid(form)
Thanks,
Chris