Roger Ineichen a écrit :
Hi Christophe

Betreff: [Zope-dev] z3c.form: unicode error with upload form


The z3c.form.converter.FileUploadDataConverter has no toWidgetValue() method. Instead, it inherits from BaseDataConverter.toWidgetValue(), that returns unicode(data).

However unicode(value) returns an error when the value is binary data!

Shouldn't FileUploadDataConverter implement its own toWidgetValue?

I guess I know what you are trying to do.
As I implemented this widget I was thinking that a file upload never get
used for representation. Becaues it allways offers only upload again
if already an uploaded file exists.

I've just an image object, that I want to upload:

class ThumbnailImageEdit(EditForm):
    fields = Fields(IImage).select('data')

So it wants to display the 'data' field, and fails. Actually not displaying anything is a reasonable default option but it should not fail. This really should be as simple as the formlib for such simple cases, without having to select a particular widget. An advanced default option would be to display the image beside the upload field, but it may be difficult to find a decent layout.


And the converter is only designed for upload files and not for convert them to widget output. Because the converter is registered for the upload widget which never should represent the content.

This means you have to use a own widget for represent a file content if it's text. And for this widget you can use another
custom converter. But sure I could be wrong. Do you see anything
which is wrong with that?

Now I guess, you are uesing the IFileWidget for your custom
widget implementation and this doesn't work, right?

See also my commit message in revision 76629:

Changed registration of file upload data converter.
Register FileUploadDataConverter for IBytes/IFileWidget.
This will force to use the data converter only for IFileWidget
and not for IBytes at all. IBytes/IWidget uses by default the

Added tests

The default widget for IBytes is the IFileWidget.

What does this mean:
If you need to use a text area widget for IBytes, you have to
register a custom widget in the form because the default widget
for IBytes is a file upload widget. You can do this by simply
set ``fields['foobar'].widgetFactory = TextWidget``.

Does this make sense to you?

Any hintes and improvments are very welcome.

Roger Ineichen


Zope-Dev maillist  -
**  No cross posts or HTML encoding!  **
(Related lists - )

Reply via email to