bootstrap-flask icon indicating copy to clipboard operation
bootstrap-flask copied to clipboard

MultiFileField handling unclear

Open WolfgangFahl opened this issue 2 years ago • 1 comments

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. grafik

Instead the Filestorage objects are of type

str: application/octet-stream

Please advise how this should be done properly.

WolfgangFahl avatar Aug 06 '21 21:08 WolfgangFahl

see also https://stackoverflow.com/questions/69310828/multi-file-field-hanlding-for-bootstrap-flask

WolfgangFahl avatar Sep 24 '21 07:09 WolfgangFahl