[Zope] uploading files

Nicolas LAURANCE nicolas.laurance@expert-rh.com
Tue, 18 Feb 2003 10:48:20 +0100


Here is my problem, I have a form like this :

<form action="Attacher_fichier" method="POST"
enctype="multipart/form-data">
Titre* :<input type="text" name="Titre:required">
<input type="file" name="file:required">
<input type="submit" name="Attacher" Value="Attacher">
</form>

************************************************************************
********************

Which ask user to input a file and give it a title

The form is then handled with a script :

************************************************************************
********************

## Script (Python) "Attacher_fichier"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=Titre, file
##title=
##

# to find the object I want to upload in, it is object manager

for obj in context.REQUEST.PARENTS:
  if obj.meta_type == "Candidature":
     Candidat=obj
     break

# create the file id
id='%s_%s' %
(DateTime().strftime('%Y%m%d%H%M%S'),random.randint(1,1000))
Candidat.manage_addProduct['OFSP'].manage_addFile(id, title=Titre,
file=file)

# redirect 
return context.REQUEST.RESPONSE.redirect(context.REQUEST.URL1)

************************************************************************
********************

My problem is, the content type is not set, it stays empty
I would like it to recognize, say application/msword or pdf or rtf or
excel files for example

I don't understand, because when I upload a file directly through ZMI
the content type is correctly set.
What did I do wrong ??

Any help appreciated
Thanxs