Index: main/waeup.sirp/trunk/src/waeup/sirp/image/browser/widget.py
===================================================================
--- main/waeup.sirp/trunk/src/waeup/sirp/image/browser/widget.py	(revision 6532)
+++ main/waeup.sirp/trunk/src/waeup/sirp/image/browser/widget.py	(revision 6533)
@@ -22,11 +22,14 @@
 """Image file widgets.
 """
+import os
 from waeup.sirp.image import WAeUPImageFile
 from hurry.file.browser.widget import (
-    FileWidgetBase, EncodingFileWidget, DownloadWidget,
-    )
+    EncodingFileWidget, DownloadWidget, FakeFieldStorage)
+from hurry.file.interfaces import IFileRetrieval
 from zope.app.form.browser.textwidgets import escape
 from zope.app.form.browser.widget import renderElement
 from zope.app.form.interfaces import ConversionError
+from zope.component import queryUtility
+from zope.publisher.browser import FileUpload
 
 
@@ -41,5 +44,5 @@
 
     def _toFieldValue(self, (input, file_id)):
-       # we got no file upload input
+        # we got no file upload input
         if not input:
             # if we got a file_id, then retrieve file and return it
@@ -59,13 +62,35 @@
 
         if data:
+            retrieval = queryUtility(IFileRetrieval)
+            if retrieval is not None:
+                seek(0)
+                return retrieval.createFile(input.filename, input)
             return WAeUPImageFile(input.filename, data)
         else:
             return self.context.missing_value
 
+    def _toFormValue(self, value):
+        if value == self.context.missing_value:
+            return self._missing
+        data = value.file.read()
+        return FileUpload(FakeFieldStorage(
+                value.filename.encode('UTF-8'), data))
+
     def __call__(self):
-        # The base widget renders the actual image as filename. We
-        # want the image itself displayed as well.
         value = self._getFormValue()
+        if value:
+            file_id = self._setFile(value)
+        else:
+            file_id = None
         result = u''
+        options = dict(
+            type=self.type,
+            name=self.name,
+            id=self.name,
+            cssClass=self.cssClass,
+            size=self.displayWidth,
+            extra=self.extra,)
+        if self.displayMaxWidth:
+            options.update(maxlength=self.displayMaxWidth)
         if value:
             filename = value.filename
@@ -77,12 +102,44 @@
                 )
             result += renderElement('br')
-        # Append the rendering as delivered from the base widget.
-        result += super(EncodingImageFileWidget, self).__call__()
+        result += renderElement(self.tag, **options)
+        if file_id is not None:
+            if value:
+                result += ' (%s)' % value.filename
+            result += renderElement(
+                'input',
+                type='hidden',
+                name=self.name + '.file_id',
+                id=self.name + '.file_id',
+                value=file_id,
+                )
         return result
+
+    def _setFile(self, file):
+        """Store away uploaded file (FileUpload object).
+
+        Returns file_id identifying file.
+        """
+        # if there was no file input and there was a file_id already in the
+        # input, reuse this for next request
+        if not self.request.get(self.name):
+            file_id = self.request.get(self.name + '.file_id')
+            if file_id is not None:
+                return file_id
+        # otherwise, stuff filedata away in session, making a new file_id
+        if file == self.context.missing_value:
+            return None
+        return self._storeFile(file)
 
     def _storeFile(self, file_upload):
         # filenames are normally in unicode encoding, while the contents
         # are byte streams. We turn the filename into a bytestream.
-        data = '%s\n%s' % (str(file_upload.filename), file_upload.read())
+        retrieval = queryUtility(IFileRetrieval)
+        if retrieval is not None:
+            file_upload.seek(0)
+            file_obj = retrieval.createFile(file_upload.filename, file_upload)
+            data = file_obj.data
+        else:
+            data = file_upload.read()
+        data = '%s\n%s' % (str(file_upload.filename), data)
         return data.encode('base64')[:-1]
 
