[Zope] How to upload files and create file objects from DTML page?
Robert Rottermann
robert@redcor.ch
Mon, 25 Mar 2002 07:47:07 +0100
This is a multi-part message in MIME format.
------=_NextPart_000_002C_01C1D3D1.435760B0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
in the method (probably a python script) dealing with the upload use the =
following
I patched it from several of my methods. It is not tested but it should =
give you the idea
Robert
Call this function as a the action of a file upload form.
If it is in a python script just leave out the def part, and give the =
script the
parameter file.
def manage_addMyFile ( self, file ) :
""" add file """
import os
if hasattr(file,'filename'):
filename=3Dfile.filename
title=3Dfilename
id=3Dfilename[max(string.rfind(filename, '/'),
string.rfind(filename, '\\'),
string.rfind(filename, ':'),
)+1:]
if(file):
if(os.path.splitext(filename)[1] in ['.jpg', '.gif']):
self.manage_addImage(id, title, file)
if other extention ....
----- Original Message -----=20
From: Mark Spencer=20
To: zope@zope.org=20
Sent: Monday, March 25, 2002 2:46 AM
Subject: [Zope] How to upload files and create file objects from DTML =
page?
I want to have a normal DTML page for users that allows them to upload =
and download files (without needing to use the management interface). =
The downloading and display of files is fine, but I cant figure out the =
zope/python code to create a new file object and store an uploaded file. =
The files could be upto ~60MB in size, and can be zip or doc files etc. =
Has anyone seen suitable sample code for this?
------=_NextPart_000_002C_01C1D3D1.435760B0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2600.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>in the method (probably a python =
script) dealing=20
with the upload use the following</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I patched it from several of my =
methods. It is not=20
tested but it should give you the idea</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Robert</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Call this function as a the action of a =
file upload=20
form.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>If it is in a python script just leave =
out the def=20
part, and give the script the</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>parameter file.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> def manage_addMyFile =
( self,=20
file ) :<BR> """ add file=20
"""<BR> import=20
os<BR> if=20
hasattr(file,'filename'):<BR> &n=
bsp; =20
filename=3Dfile.filename<BR> &nb=
sp; =20
title=3Dfilename<BR>  =
; =20
id=3Dfilename[max(string.rfind(filename,=20
'/'),<BR> &nbs=
p;  =
; =20
string.rfind(filename,=20
'\\'),<BR> &nb=
sp; &nbs=
p; =20
string.rfind(filename,=20
':'),<BR> &nbs=
p;  =
; =20
)+1:]</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial =
size=3D2> =20
if(file):<BR> =
=20
if(os.path.splitext(filename)[1] in ['.jpg',=20
'.gif']):<BR> =
=20
self.manage_addImage(id, title,=20
file)<BR> &nbs=
p; if=20
other extention ....<BR></DIV></FONT>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV=20
style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
<A title=3Dmarkwspencer@bigpond.com =
href=3D"mailto:markwspencer@bigpond.com">Mark=20
Spencer</A> </DIV>
<DIV style=3D"FONT: 10pt arial"><B>To:</B> <A title=3Dzope@zope.org=20
href=3D"mailto:zope@zope.org">zope@zope.org</A> </DIV>
<DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Monday, March 25, 2002 =
2:46=20
AM</DIV>
<DIV style=3D"FONT: 10pt arial"><B>Subject:</B> [Zope] How to upload =
files and=20
create file objects from DTML page?</DIV>
<DIV><BR></DIV>
<DIV><FONT face=3DArial>I want to have a normal DTML page for users =
that allows=20
them to upload and download files (without needing to use =
the=20
management interface). The downloading and display of files is fine, =
but I=20
cant figure out the zope/python code to create a new file object =
and=20
store an uploaded file. The files could be upto ~60MB in size, =
and can be=20
zip or doc files etc. Has anyone seen suitable sample code for=20
this?</FONT></DIV></BLOCKQUOTE></BODY></HTML>
------=_NextPart_000_002C_01C1D3D1.435760B0--