[Zope-CMF] cPickled Error when uploading a file
Karim Yaici
karimy@nipltd.com
Fri, 22 Jun 2001 11:26:01 +0100
Hi,
I have created a small Portal content type which allows you to combine
structured text and file attachments. I was inspired by 'ComplexDocument'
;-).
My docuement is 'folderish' and that's where I want my files to be uploaded
to. If I don't upload a file every thing works but when I try using a
attachments I get the following error:
Error Type: cPickle.PicklingError
Error Value: Cannot pickle objects.
<.....>
File C:\Program Files\Zope\2.3.2\lib\python\ZODB\Connection.py, line 375, in
commit
(Info: (('Products.MyProduct', 'MyDocument'),
'\000\000\000\000\000\0000}', ''))
cPickle.PicklingError: (see above)
Here is the code that does the upload (again, heavily inspired by
ComplexDocument):
filenamepattern=re.compile(r'[A-Za-z0-9][\w\_\-\.]*$')
def add_file(self, sf):
basename,title = cookId('','',sf)
if not filenamepattern.match(basename):
return
suffix=os.path.splitext(basename)[1]
folder=self
if folder:
if string.lower(suffix) in ['.htm', '.html']:
folder.manage_addDTMLDocument(id=basename, title='',
file=sf)
elif string.lower(suffix) in ['.gif', '.jpg', '.jpeg', '.png']:
folder.manage_addImage(id=basename, title='', file=sf)
elif len(suffix)==0 and basename[-5:] == "_html":
folder.manage_addDTMLDocument(id=basename, title='',
file=sf)
else:
folder.manage_addFile(id=basename, title='', file=sf)
The code exits happily from this method, but then without the file upload
every thing works fine. Probably a FileUpload object (that I get from the
form) is not appropriate to pass into manage_addFile.
Any suggestions?
Thank you in advance.
Karim