RE: [Zope] picture as parameter for an external method / thumbnail
Hi You are right Dragos ! Your code is working fine with the read() method and the picture is well provided to the external method. Many thanks to you and Tino. I have now added some extra code in the external method to create a thumbnail from the picture. But unfortunately the same "exceptions.assertionError" happens again :- ( ( If i'm only leaving the first real code line (getattr), the error already appear. Creating a thumbnail seems to be something tricky as another user of zope community had also somme problems (other errors message) with that matter this morning... Any hint ? Anyway thanks for the help ! def makethumbnail(self, original_id): from PIL import Image from StringIO import StringIO import os.path # create a thumbnail image file original_image=getattr(self, original_id) original_file=StringIO(str(original_image.data)) image=Image.open(original_file) image=image.convert('RGB') image.thumbnail((size,size)) thumbnail_file=StringIO() image.save(thumbnail_file, "JPEG") thumbnail_file.seek(0) # create an id for the thumbnail path, ext=os.path.splitext(original_id) thumbnail_id=path + '.thumb.jpg' # if there's and old thumbnail, delete it if thumbnail_id in self.objectIds(): self.manage_delObjects([thumbnail_id]) # create the Zope image object IN MY OWN LOCAL FILE SYSTEM self.phvfs.manage_addProduct['OFSP'].manage_addImage(thumbnail_id,thumbnai l_file,'thumbnail image') thumbnail_image=getattr(self, thumbnail_id) # set the 'originial_id' property thumbnail_image.manage_addProperty('original_id', original_id, 'string') REGARDS Ph. -----Original Message----- From: Dragos Chirila [mailto:d.chirila@finsiel.ro] Sent: lundi 11 octobre 2004 17:20 To: zope@zope.org; VIGNAUX Philippe Subject: Re: [Zope] picture as parameter for an external method Hi I just simulate your situation and it works great. I attached the picture.zexp file that generates a folder with : upload_html - page template py_test - python script my_external_function - external method The my_external_function.py from extensions contains just: def my_external_function(self, picture): print type(picture) print picture I tested it on Zope 2.5.1 and 2.6.4. Hope this will help. Dragos VIGNAUX Philippe wrote:
Thanks for your help Tino,
1) For clarity purpose here is the whole page template
<html> <head> <title> Titre </title> </head> <body> <form action="py_test" enctype='multipart/form-data' method='post'> <input type="file" name="filename"> <br><br> <input type="submit" name="toto"> </form> </body> </html>
2) here is the python script "py_test"
request=context.REQUEST context.my_external_function( original_id=request['filename'] ) #context.my_external_function( original_id=request.form.get('filename') ) #context.my_external_function( request['filename'] )
!!nb: the 2 commented lines do not change anything to the error message ...
3) my_external_function
def my_external_function (self, original_id): pass
Of course this external method is supposed to do much more. I hope to be able to create thumbnail (as an example seen in the zope book). But i have simplified it as much as possible to see where the problem was located. I'm sure i ll have other problems to create the thumbnails ... : - ) but the real problem at this time is to pass a picture to the exernal method ...
Regards
Ph.
-----Original Message----- From: Tino Wildenhain [mailto:tino@wildenhain.de] Sent: lundi 11 octobre 2004 12:53 To: VIGNAUX Philippe Cc: zope@zope.org Subject: Re: [Zope] picture as parameter for an external method
On Mon, 2004-10-11 at 11:58, VIGNAUX Philippe wrote:
Hi !
Is there a way to pass a picture (extension JPG) as a parameter of an external method. It seem to be the case as read on the internet but for me it doesnÿt work ! My zope config : Zope 2.6.4 (binary release, python 2.1, win32-x86), python 2.1.3, win32 This is the problem : 1) Iÿve got a page template where I can choose a picture thru a « file » object : <input type="file" name="filename">
Did you adjust enctype accordingly?
2) This page template calls a python scripts
Calls? The Template is target of the POST request too?
request=context.REQUEST context.my_external_function( original_id=request['filename'] ) #context.my_external_function( request['filename'] )
if you do it the right way[tm] (see the enctype you can borrow from any ZMI HTML source which has a file upload) request.form.get('filename') will give you a file object. (If you return from form of course)
3) my_external_function is defined in an appropiate module in the « Extensions » folder of my zope installation
def my_external_function (self, original_id):
pass
This is all?
PROBLEM : when i run the process i get an error :
exceptions.AssertionError
Sorry, a site error occurred.
Traceback (innermost last):
* Module ZPublisher.Publish, line 150, in publish_module * Module ZPublisher.Publish, line 106, in publish * Module Zope.App.startup, line 225, in abort * Module ZODB.Transaction, line 135, in abort * Module ZODB.Connection, line 256, in abort
When i configure the whole thing to pass a normal parameter (text), it works normally ; so obviously the problem is when trying to pass a picture.
This might be related to the enctype. Try it first I'd say. What is your external method supposed to do?
Regards Tino
###########################################
This message has been scanned by ICT - Africa Museum
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Dragos Chirila Programmer, Finsiel ROMANIA 44A, Ficusului St. - 71544 Bucharest Tel: +40 21 2320193 Fax: +40 21 2329807 URL: http://www.finsiel.ro Jabber: dragos@jabber.finsiel.ro ########################################### This message has been scanned by ICT - Africa Museum
participants (1)
-
VIGNAUX Philippe