helloflask / flask-dropzone

Upload files in Flask application with Dropzone.js.
https://flask-dropzone.readthedocs.io
MIT License
250 stars 69 forks source link

Pass filename to redirect_url #38

Closed akent-q closed 4 years ago

akent-q commented 4 years ago

What's the best way to pass the uploaded filename(s) to the redirect url? e.g. something like:

{{ dropzone.config( redirect_url=url_for('view', file=filename) ) }}
greyli commented 4 years ago

You can't pass the filename like this since this function call will be rendered before the file was uploaded. Instead, you can store the filename in database or session in upload view, then get it back from the database or session:

from flask import session

@app.route('/upload')
def upload():
    # ...
    session['filename'] = the_filename

@app.route('/view')
def the_redirect_view():
    filename = session.get('filename)
akent-q commented 4 years ago

Perfect. Thanks