Index: /WAeUP_SRP/base/WAeUPTool.py
===================================================================
--- /WAeUP_SRP/base/WAeUPTool.py	(revision 2353)
+++ /WAeUP_SRP/base/WAeUPTool.py	(revision 2354)
@@ -696,6 +696,9 @@
         response = self.REQUEST.RESPONSE
         #import pdb;pdb.set_trace()
+        registry = getToolByName(self, 'mimetypes_registry')
+        mimetype = str(registry.lookupExtension(path.lower()) or
+                    registry.lookupExtension('file.bin'))
         if os.path.exists(picture_path):
-            response.setHeader('Content-type','image/jpeg')
+            response.setHeader('Content-type',mimetype)
             return open(picture_path).read()
         picture_path = os.path.join(i_home,'import',path)
Index: /WAeUP_SRP/base/Widgets.py
===================================================================
--- /WAeUP_SRP/base/Widgets.py	(revision 2353)
+++ /WAeUP_SRP/base/Widgets.py	(revision 2354)
@@ -6,4 +6,5 @@
 from Globals import InitializeClass
 from ZPublisher.HTTPRequest import FileUpload
+from OFS.Image import cookId, File, Image
 ##from Products.CPSSchemas.Widget import CPSWidgetType
 from Products.CMFCore.utils import getToolByName
@@ -1796,7 +1797,35 @@
     show_image = False
 
+    def getStorageImageInfo(self,field_id):
+        info = {}
+        if self.id_field == "":
+            student_id = self.getStudentId()
+        else:
+            student_id = datastructure[self.id_field]
+        student_path = os.path.join(self.storage_path,
+                                    student_id)
+        image_name = ''
+        content_url = ''
+        current_filename = ''
+        for name in os.listdir(student_path):
+            if name.startswith(field_id):
+                image_name = name
+                break
+        if image_name:
+            info['image_name'] = image_name
+            info['content_url'] = os.path.join(self.portal_url(),
+                                   "viewimage",
+                                   self.path,
+                                   student_id,
+                                   image_name,
+                                   )
+            info['current_filename'] = os.path.join(student_id,
+                                                    image_name)
+            info['file_path'] = os.path.join(self.storage_path,
+                                             info['current_filename'])
+        return info
+            
     def getImageInfo(self, datastructure): ###(
         """Get the file info from the datastructure."""
-        #import pdb; pdb.set_trace()
         widget_id = self.getWidgetId()
         if  datastructure.has_key(widget_id):
@@ -1804,24 +1833,13 @@
             dm = datastructure.getDataModel()
             field_id = self.fields[0]
-            if self.id_field == "":
-                student_id = self.getStudentId()
-            else:
-                student_id = datastructure[self.id_field]
-            content_url = os.path.join(self.portal_url(),
-                                       "viewimage",
-                                       self.path,
-                                       student_id,
-                                       "%s_%s.jpg" % (self.getWidgetId(),student_id),
-                                       )
-            image_title = "%s_%s.jpg" % (widget_id,student_id)
-            current_filename = os.path.join(student_id,
-                                            image_title)
-            file_path = os.path.join(self.storage_path,
-                                     current_filename)
+            info = self.getStorageImageInfo(field_id)
         else:
             file_path = "XXX"
-            image_title = ""
+            title = ""
         # read the file from the filesystem
-        if not os.path.exists(file_path):
+        #import pdb; pdb.set_trace()
+        #if not os.path.exists(file_path):
+        if not info:
+            title = ""
             height = -1
             width = -1
@@ -1836,5 +1854,8 @@
             width = ''
         else:
-            image = open(file_path)
+            title = info['image_name']
+            current_filename = info['current_filename']
+            content_url = info['content_url']
+            image = open(info['file_path'])
             from OFS.Image import getImageInfo as getImageInfoOFS
             image.seek(0)
@@ -1869,5 +1890,4 @@
                     height = int(zoom * height)
                 #import pdb;pdb.set_trace()
-        title = image_title
         image_info = {
             'empty_file': empty_file,
@@ -1897,9 +1917,9 @@
     ###)
 
-    def checkFileName(self, filename, mimetype):
-        return '', {}
-        if mimetype and mimetype.startswith('image'):
-            return '', {}
-        return 'cpsschemas_err_image', {}
+    # def checkFileName(self, filename, mimetype):
+    #     return '', {}
+    #     if mimetype and mimetype.startswith('image'):
+    #         return '', {}
+    #     return 'cpsschemas_err_image', {}
 
     def prepare(self, datastructure, **kw): ###(
@@ -1935,8 +1955,4 @@
         mimetype = None
         old_file = datamodel[field_id]
-        # if old_file is not None:
-        #     old_filename = old_file.title
-        # else:
-        #     old_filename = ''
         choice = datastructure[widget_id+'_choice']
         fileupload = datastructure[widget_id]
@@ -1955,13 +1971,8 @@
                 return self.validateError('cpsschemas_err_required', {},
                                           datastructure)
-            ext ='jpg'
-            filename = "%s_%s.%s" % (self.getWidgetId(),
-                                     student_id,
-                                     ext)
+            info= self.getStorageImageInfo(field_id)
             # Remove the file in the filesystem
-            student_path = os.path.join(self.storage_path,student_id)
-            full_path = os.path.join(student_path, filename)
-            if os.path.exists(full_path):
-                os.remove(full_path)
+            if info:
+                os.remove(info['file_path'])
             datamodel[field_id] = None
         elif choice == 'keep':
@@ -1999,8 +2010,9 @@
         # Find filename
         if is_upload and store:
-            ext ='jpg'
-            filename = "%s_%s.%s" % (self.getWidgetId(),
-                                     student_id,
-                                     ext)
+            filename = cookId('', '', fileupload)[0].strip()
+            base,ext = os.path.splitext(filename)
+            filename = "%s_%s%s" % (field_id,
+                                    student_id,
+                                    ext)
             datamodel[field_id] = filename
             registry = getToolByName(self, 'mimetypes_registry')
@@ -2017,5 +2029,4 @@
                 os.mkdir(student_path)
             full_path = os.path.join(student_path, filename)
-            #import pdb;pdb.set_trace()
             pict = open(full_path,"w")
             fileupload.seek(0)
@@ -2023,6 +2034,5 @@
             pict.close()
         return True
-
-###)
+    ###)
 
     def render(self, mode, datastructure, **kw): ###(
