How to actually upload a file using Flask WTF FileField


In my file I have I have

    class myForm(Form):
       fileName = FileField()

In my file I have

    form = myForm()
    if form.validate_on_submit():
        fileName = secure_filename(form.fileName.file.filename)

In my .html file I have

     {% block content %}
     <form action="" method="post" name="simple" enctype="multipart/form-data">
           Upload a file
        <p><input type="submit" value="Submit"></p>
     {% endblock %}

and it seems to work when I hit submit but the file is not in any of the project directories.

1/29/2013 6:09:26 PM

Accepted Answer

I just had to call .save on

    myFile = secure_filename(form.fileName.file.filename)
1/29/2013 6:47:38 PM

Have you looked at this:

You have to set a few configs such as UPLOAD_FOLDER etc. You also have to call the save() function which I don't see in your posted code for['UPLOAD_FOLDER'], filename))

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow