Hello,

Just spent a few hours trying to figure out why my FileField() with
FieldStorageUploadConverter() validation worked fine using the TW-
generated template (returning a FieldStorage object) but returns only
a Unicode object when I try to use my own custom template.  Though TG
2.1 docs touch on the solution (See 
http://turbogears.org/2.1/docs/main/ToscaWidgets/forms.html
- "Adding a File Upload") I though I might leave a note here to make
Googling for a solution a bit easier.

To summarize:  Make sure your template contains enctype="multipart/
form-data" in <form>:

My Widget:

class OrderForm(twd.CustomisedForm):
  submit_text = 'Save Order'
  # Using OrderForm returns document_scan as Unicode.  Comment the
template and document_scan
  # correctly returns a FieldStorage object
  template = "Project.templates.OrderForm"

fields = [
..
FileField('document_scan', label_text = 'Paperwork Scan',
help_text='Click to upload document scans',
validator=FieldStorageUploadConverter(if_invalid=None))
..
]

A correct template form definition in OrderFrom.html:

<form xmlns="http://www.w3.org/1999/xhtml"; xmlns:py="http://
genshi.edgewall.org/" xmlns:xi="http://www.w3.org/2001/XInclude";
name="${name}" action="${action}" method="${method}"
class="OrderFormTop-Test" enctype="multipart/form-data">
 
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Be sure to put in enctype to let the server know to expect multipart
message.

Hope this helps somewhere.

- Shane

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en.

Reply via email to