Re: Re: buildZipArchive
Thorsten Weber <[email protected]> Mon, 9 May 2011 10:43:43 +0200
| Newsgroups | gmane.comp.cms.zms.devel |
|---|---|
| Message-ID | <[email protected]> |
Now I write zipfile "by hand" to temp dir in py script:
context.localfs_write(tempfolder + '/' + filename.rsplit('.')[0] + '.zip', exportfile, mode='b')
and read it back to zms:
<dtml-let zipFile="localfs_read(tempfolder + '/' + filename.rsplit('.')[0] + '.zip', mode='b', REQUEST=None)">
<dtml-call "setObjProperty('image_file',zipFile,lang)">
</dtml-let>
but this gives me:
Exception Type TypeError
Exception Value coercing to Unicode: need string or buffer, filestream_iterator found
Traceback (innermost last):
Module ZPublisher.Publish, line 125, in publish
Module Zope2.App.startup, line 238, in commit
Module transaction._manager, line 96, in commit
Module transaction._transaction, line 395, in commit
Module transaction._transaction, line 495, in _commitResources
Module ZODB.Connection, line 502, in commit
Module ZODB.Connection, line 1046, in savepoint
Module ZODB.Connection, line 555, in _commit
Module ZODB.Connection, line 582, in _store_objects
Module ZODB.serialize, line 407, in serialize
Module ZODB.serialize, line 416, in _dump
Module copy_reg, line 70, in _reduce_ex
TypeError: coercing to Unicode: need string or buffer, filestream_iterator found
Any ideas for that?
regards, Thorsten
Am 06.05.2011 um 15:26 schrieb Thorsten Weber:
>
>
> what I want to do is ...
> an image uploaded into ZMS should be zipped and stored in a field of type file.
>
> I tested it with a given image object (myImage) within zms ... which worked.
>
> <dtml-let myImage ="getObjProperty('myImage',REQUEST)">
> <dtml-call "setObjProperty('file', myImage,lang)">
> </dtml-let>
>
> now to my problem :
> therefore I wanted to adapt the python script mentioned in the article below.
> http://www.zms-publishing.com/dokumentation/magic/zip_archive_erstellen/index_ger.html
>
> in ZMS home folder i created a python script - named packZip - with two parameters (tempfolder, filename)
>
> tempfolder is created by localfs_tempfile() command
>
> <dtml-let file="getObjProperty('myImage',REQUEST)" filename="file.getFilename()" tempfolder="localfs_tempfile()">
>
> then the image is copied to the temporary folder
>
> <dtml-call "localfs_write('%s/%s'%(tempfolder,filename),file.getData(),mode='b')">
>
> this works so far.
>
> i call the python script like this:
>
> <dtml-let zipFile="packZip(tempfolder,filename)">
> <dtml-call "setObjProperty('zipfile',zipFile,lang)">
> </dtml-let>
>
> this python script (packZip) builds a zipfile (in memory or in system filesystem) and asigns the zipfile to the variable exportfile
> exportfile is the return value of a python script:
>
> exportfile = context.buildZipArchive( '%s/*.*'%tempfolder )
> return exportfile
>
> even writing the exportfile into tempfolder within the python script works.
>
> this all seems to work properly ... but i can not store the returned exportfile in zms.
> when trying to store it in a text field there is a lot of junk .. . but it seems to work somehow - so to say: there some data which is returned by the python script. ;)
>
> I hope this makes the problem more clear.
>
> regards, Thorsten
>
>
> Am 06.05.2011 um 14:54 schrieb Thorsten:
>
>>
>> well, starting with the thin contextual information on your problem:
>> Find out the difference between "myImage" and "exportfile", the latter seems to be unkoscher ...
>>
>> --- In [email protected], Thorsten Weber <tweber@...> wrote:
>> > Nop.
>> > Sorry ... but this does not the trick. :(
>> > and as I said: it works with images.
>> >
>> > Any other ideas?
>> >
>> >
>> > Am 06.05.2011 um 14:09 schrieb Thorsten:
>> >
>> > > might be a missing
>> > > <dtml-call "setObjStateModified(REQUEST)">
>> > > before setObjProperty()?
>> > >
>> > > Greetings, tf
>> > >
>> > > --- In [email protected], Thorsten Weber <tweber@> wrote:
>> > > ...
>> > > > I am trying to generate a zip file on server and store it in archtype file field.
>> > > >
>> > > > <dtml-call "setObjProperty('zip_file',exportfile,lang)">
>> > > >
>> > > > I followed this article (http://www.zms-publishing.com/dokumentation/magic/zip_archive_erstellen/index_ger.html)
>> > > > but unfortunately it does not work for me:
>> > > >
>> > > > I can see on server the temp dir and in it the file to be zipped and the py-script returns exportfile but i dont get it stored in zms file field.
>> > >
>> > >
>> >
>>
>
>
>