Zope products and uploading files
Dear all At the moment I am creating a small zope product that is the web front end to a java pipeline. I have a form where I can upload a file and I can successfully place it anywhere within the Zope database by using context.manage_addFile(name,file,title) The file that is uploaded does not really want to be in zope - it should be somewhere on the local filesystem - I have tried to read the file contents back to the filesystem - but the product dies with a Attribute Error :: __call__ Or POSKeyError 000000000267f or something like it. I could use Java to extract the contents of the URL but this seems quite silly. I know that I am doing it the hard way - could someone kindly suggest to me an elegant way to write the File object directly to the local disk? Any help would be very gratefully received. Thanks Stephen
Stephen Rudd wrote:
Dear all
At the moment I am creating a small zope product that is the web front end to a java pipeline. I have a form where I can upload a file and I can successfully place it anywhere within the Zope database by using
context.manage_addFile(name,file,title)
The file that is uploaded does not really want to be in zope - it should be somewhere on the local filesystem - I have tried to read the file contents back to the filesystem - but the product dies with a
Get the content from the data attribute. -- hilsen/regards Max M, Denmark http://www.mxm.dk/ IT's Mad Science
On 03.Feb 2005 - 16:49:43, Stephen Rudd wrote:
Dear all
At the moment I am creating a small zope product that is the web front end to a java pipeline. I have a form where I can upload a file and I can successfully place it anywhere within the Zope database by using
context.manage_addFile(name,file,title)
The file that is uploaded does not really want to be in zope - it should be somewhere on the local filesystem - I have tried to read the file contents
Hmm, the REQUEST has a FileUpload Object (or something similar) for each file, this in turn has a member "data", which holds the actual data. So you could just take that and pass it to a normal python file I/O function (I don't know how these are called)... To examine further members of the Object you could do something like for member in dir(REQUEST['name_of_fileinput']): print member return printed Andreas -- You will overcome the attacks of jealous associates.
Andreas Pakulat wrote at 2005-2-3 16:29 +0100:
... Hmm, the REQUEST has a FileUpload Object (or something similar) for each file, this in turn has a member "data", which holds the actual data. So you could just take that and pass it to a normal python file I/O function (I don't know how these are called)...
Where have your seen a "data" member of a "ZPublisher.HTTPRequest.FileUpload" object? In fact, "FileUpload" objects do not have such an attribute (Zope's "File" objects have). You can use file methods ("read", "seek", ...) to access the content of "FileUpload" objects. -- Dieter
Hello. I would like to decode/encode data in base64 without resorting to an external Python method. Every function that I tried to use in a Python script, such as mimetools.[encode|decode], binascii.[a2b_base64|b2a_base64], base64.[b64encode|b64decode] returns an error: Error Type: Unauthorized Error Value: You are not allowed to access encode in this context Does anyone know a way to do this?
Hi You are not allowed to access base64 modules from python scripts. A solution for this is to write a small product. In your Products folder add a folder called let's say GiveAccess and inside add a file __init__.py The body of the file is: from AccessControl import allow_module allow_module('base64') Restart your Zope. Now you can use base64 in python scripts. Regards, Dragos Andrea Lombardoni wrote:
Hello.
I would like to decode/encode data in base64 without resorting to an external Python method.
Every function that I tried to use in a Python script, such as mimetools.[encode|decode], binascii.[a2b_base64|b2a_base64], base64.[b64encode|b64decode] returns an error:
Error Type: Unauthorized Error Value: You are not allowed to access encode in this context
Does anyone know a way to do this?
_______________________________________________ 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 )
On Fri, 4 Feb 2005 13:58:20 +0100 (CET), Andrea Lombardoni <lombardo@inf.ethz.ch> wrote:
I would like to decode/encode data in base64 without resorting to an external Python method.
The following is in the Python interpreter, but I have verified that it works for Python scripts in Zope. Python 2.3.4 (#1, Jul 30 2004, 09:49:24) [GCC 3.3.4 20040623 (Gentoo Linux 3.3.4-r1, ssp-3.3.2-2, pie-8.7.6)] on linux2 Type "help", "copyright", "credits" or "license" for more information.
"Hello World!".encode('base64') 'SGVsbG8gV29ybGQh\n' 'SGVsbG8gV29ybGQh\n'.decode('base64') 'Hello World!' 'Clguba ebpxf!'.decode('rot13') u'Python rocks!'
-- Computer interfaces should never be made of meat. Using GMail? Setting Reply-to address to <> disables this annoying feature.
participants (7)
-
Andrea Lombardoni -
Andreas Pakulat -
Andy Dustman -
Dieter Maurer -
Dragos Chirila -
Max M -
Stephen Rudd