My goal is to allow registered users to upload files (numbering the hundreds) to a staging area, after passing through Django authentication and selecting the target directory using a identifier registered to them that is used to look up the target in a db table. While I’m not convinced that the multiple file uploader is the best way to go, as I’d prefer the clients to be non-interactive (i.e., run from cron), I thought I’d start this way…
From the Django documentation, I created the form & view verbatim, filling in the values for the template_name and success_url. When I try to use it, the form displays, and gives me a choose file button. Clicking the button brings up the file dialog and I can select multiple files. When I close the dialog it shows 5 files next to the button. When I submit, it goes to the page I provided in success_url.
The problem is that when the clean method of the MultipleFileField class is called, the data parameter points to an empty list, verified with print statements - so there is nothing to clean. The empty list is assigned by the FileFieldForm class to the file_field variable which appears in the view.
There is no example template in the documentation, so here is the one I used, which borrows its formatting from the django admin model.
{% extends "admin/base.html" %}
{% load i18n %}
{% spaceless %}
<html>
<head>
{% load static %}
{% block title %}
Upload Recordings
{% endblock %}
{% block extrahead %}
<link rel="icon" type="image/png" href="{% static 'images/favicon_64x64.png' %}" >
{% endblock %}
</head>
<body>
{% block branding %}
<h1 id="site-name">{% trans 'Upload Recordings' %}</h1>
{% endblock %}
{% block content %}
<form method="post">
{% csrf_token %}
{{ form }}
<button name="submit">Submit</button>
</form>
{% endblock %}
</body>
</html>
{% endspaceless %}
Django 5.0.6, Python 3.12.3, Windows 11. Running in Django runserver with debug enabled.