July 15th, 2003, 03:00 PM
Pass a file from DMTL to Python script
I need to pass a file from DTML document to python script via an External Method.
Problem: the python script is not receiving the file correctly. I'm not getting an error... it's just an empty file.
I have the following in my code:
and the file is of <...type="file" name="thefile"...>
I'm calling the external method "convert" like this:
However, when I return thefile in the python script to see if it contains anything, it's returning an empty file. (I varified the contents of the file... it's not empty!!)
What am I doing wrong??? Thanks....
July 15th, 2003, 03:56 PM
Hi, could you not run this as a python script in zope and use the request handle to get the data from the file? Or if the file is on the server already, can you read it in from the python script. What exactly is the perpos of this page anyway? If it's just file upload then I'm sure there are already a few dtml methods out there, there may even be a dtml upload tag. I'm looking into external methods ill let you know if i figure something out.
July 16th, 2003, 08:25 AM
I can't run the script in Zope because of some of the imports I'm having to do. (example: from sgmllib import SGMLParser) This is why I have to use an External Method.
The purpose of the script is to convert a HTML/XML file to plain text. The DocumentLibrary in Zope allows for this conversion, but I need to do it programmatically. I'm actually using the html.py script that the DocumentLibrary uses.
I allow the user to choose a file from his/her computer to convert to plain text. The problem is that when I send the file from the DTML method to the python script, it's empty when it reaches the script.
I hope this explains what I'm trying to do. Thanks for your help. I really appreciate it.
July 16th, 2003, 09:30 AM
Yeah i see, ok if i break this down. The way i see it, you have an external method which you want to send the data from the file stream. If you are passing data to a python function within the external method (dont know how you do this yet) you need to prosess the form and pass the data from the file field to the external method and then get the output (which i believe happens automatically)
Something like this but i dout this would work..
Hope this helps am still trying to get my head around zope
<dtml-var "convert(<dtml-var "file field">)">