[Zope] Upload a Zclass with a script

Sedat Yilmazer sedat@kibele.com
Mon, 9 Jul 2001 18:47:02 +0300


 Hi
You need to pass a file object back, not a string.. So I just patched up =
your code to return a StringIO file object ( I have not tried it)



import sys,os,string
from OFS.Image import File

import StringIO     <=3D=3D=3D=3D=3D=3D=3D

def get_data:
    file=3Dopen('c:\test.txt','rb')

    data=3D StringIO(file.read()) <=3D=3D=3D=3D=3D=3D=3D

    file.close()
    return data


 Probably you can pass the f'le object back as well but then somewhere =
you have to close it/

 Regards
 Sedat


-----Original Message-----
From: Christophe Bec [mailto:christophe.bec@cgey.com]
Sent: Monday, July 09, 2001 5:28 PM
To: Sedat Yilmazer
Subject: Re: [Zope] Upload a Zclass with a script


ok i've tried this external method called get_data :

get_data.py
___________________
___________________

import sys,os,string
from OFS.Image import File

def get_data:
    file=3Dopen('c:\test.txt','rb')
    data=3Dfile.read()
    file.close()
    return data


and when icall <dtml-var "REQUEST.set('file',<dtml-var get_data>)"> i =
've an
error

thanks






----- Message d'origine -----
De : "Sedat Yilmazer" <sedat@kibele.com>
=C0 : "'Christophe Bec'" <cbec@capgemini.fr>
Envoy=E9 : lundi 9 juillet 2001 16:19
Objet : RE: [Zope] Upload a Zclass with a script



 IMHO reading a local file via DTML is not allowed. Best workaround is =
an
external python method. You need to create a file object since most of =
the
upload file managers look at the filename / content type etc.


-----Original Message-----
From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of
Christophe Bec
Sent: Monday, July 09, 2001 4:49 PM
To: zope@zope.org
Subject: [Zope] Upload a Zclass with a script


Hi,

I've a Zclass with "File" inheritance
How can i do to upload a file with a script during instanciation (dtml =
or
python)
trying <dtml-var "REQUEST.set('file','c:\test.txt')">  gives me a =
instance,
taking  'c:\test.txt' as a string and not as an object

Thanks