picture as parameter for an external method
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"> 2) This page template calls a python scripts request=context.REQUEST context.my_external_function( original_id=request['filename'] ) #context.my_external_function( request['filename'] ) 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 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. Any idea ???? Thanks Philippe ########################################### This message has been scanned by ICT - Africa Museum
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
Hi I assume that you set the following attribute for your form tag: enctype="multipart/form-data". Put a parameter in your python script called "filename" and process the form this way: picture = None if filename != '' if hasattr(filename, 'filename'): if filename.filename != '': picture = filename.read() and pass the "picture" parameter which is actually the picture (bytes). Dragos 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">
2) This page template calls a python scripts
request=context.REQUEST
context.my_external_function( original_id=request['filename'] )
#context.my_external_function( request['filename'] )
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
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.
Any idea ????
Thanks
Philippe
###########################################
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
participants (3)
-
Dragos Chirila -
Tino Wildenhain -
VIGNAUX Philippe