bootstrap-flask
bootstrap-flask copied to clipboard
MultiFileField handling unclear
I am trying to get http://fb4demo.bitplan.com/upload to work with the following code:
class UploadForm(FlaskForm):
'''
upload form example
'''
file = MultipleFileField('File(s) to Upload')
submit = SubmitField()
{% extends 'base.html' %}
{% from 'bootstrap/form.html' import render_form, render_field, render_form_row %}
{% block content %}
<!-- https://github.com/greyli/flask-dropzone/issues/29 -->
<script type="text/javascript">
Dropzone.options.myDropzone.headers = {"X-CSRF-Token": "{{ csrf_token() }}"}
</script>
<h1>Upload Form</h1>
{{ render_form(upload_form) }}
{{ dropzone.create(action=url_for('test_upload')) }}
{{ dropzone.config() }}
{% endblock %}
def upload(self):
'''
handle the uploading
'''
form= UploadForm()
filenames=""
delim=""
if form.validate_on_submit():
for file in form.file.data:
file_filename = secure_filename(file.filename)
filePath=f'/tmp/{file_filename}'
with open(filePath, 'wb') as f:
f.write(file.read())
size=os.path.getsize(filePath)
filenames=f"{filenames}{delim}{file_filename}({size})"
delim="<br/>"
flash(Markup(filenames))
return render_template('upload.html',upload_form=form)
drag and drop works except #147 but when clicking submit the filenames are no available.
Instead the Filestorage objects are of type
str: application/octet-stream
Please advise how this should be done properly.
see also https://stackoverflow.com/questions/69310828/multi-file-field-hanlding-for-bootstrap-flask