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
Nicolas LAURANCE wrote at 2003-2-18 10:48 +0100:
... uploading file does not set content_type ... 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.
I do not know why it does not work automatically. However, the "ZMI" uses the "id" as an additional source to guess the content type. Check the source in "OFS/Image.py", to learn how it works (and why it does not in your case). If you know the content type, you can pass it directly to "addFile". Dieter
participants (2)
-
Dieter Maurer -
Nicolas LAURANCE