helloflask / helloflask/bootstrap-flask

MultiFileField handling unclear

Open
#148 1 comment 0 reactions 0 assignees View on GitHub
form
Dominant language
SCSS
Stars
1.2k
Forks
193
Avg merge
4m
Merged PRs (30d)
3

Description

I am trying to get http://fb4demo.bitplan.com/upload to work with the following code:
```python
class UploadForm(FlaskForm):
'''
upload form example
'''
file = MultipleFileField('File(s) to Upload')
submit = SubmitField()
```

```html
{% extends 'base.html' %}
{% from 'bootstrap/form.html' import render_form, render_field, render_form_row %}

{% block content %}

Dropzone.options.myDropzone.headers = {"X-CSRF-Token": "{{ csrf_token() }}"}

Upload Form


{{ render_form(upload_form) }}
{{ dropzone.create(action=url_for('test_upload')) }}
{{ dropzone.config() }}
{% endblock %}
```

```python
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="
"
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.
![grafik](https://user-images.githubusercontent.com/1336221/128574306-0b93091e-f106-4002-933a-1ec9776fa70d.png)

Instead the Filestorage objects are of type
```
str: application/octet-stream
```
Please advise how this should be done properly.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.