#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    9
    Rep Power
    0

    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:
    <...method="post" enctype="multipart/form-data"...>
    and the file is of <...type="file" name="thefile"...>

    I'm calling the external method "convert" like this:
    <dtml-var "convert(thefile)">

    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....
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    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.

    Take care,

    Have fun,
    Mark.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    9
    Rep Power
    0
    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.
  6. #4
  7. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    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..

    Code:
    <dtml-var "convert(<dtml-var "file field">)">
    Hope this helps am still trying to get my head around zope

    Take care,
    Mark.

IMN logo majestic logo threadwatch logo seochat tools logo