3

I am trying to capture the filename of an uploaded file via a wtforms FileField

in my validator

    def checkfile(form,field):
            print form
            print field

the 'print forms' statement shows: forms.ticket.TicketForm object at 0x1d2a350

the 'print fields' statement shows: input id="files" name="files" type="file"

if i try to access field.file or field.files i get the error: 'FileField' object has no attribute 'file(s)'

field.data is empty

so how can i access the filename to run a validator?

relevant portion of my class:

class MyForm(wtforms.Form):
     files = wtforms.FileField('Files',[checkfile])

which is rendered in my template as:

   <form enctype="multipart/form-data" class="form-horizontal" name="add_ticket"      action="/ticket/add" method="post">
 <input type="hidden" name="_xsrf" value="xxxxxxxxxx"/>
 <input class="input-medium" id="files" name="files" type="file">
 </form>

0 Answers0