Re: [Zope] Yet another newbie question (file upload and python scripts)
Janusz Zamecki wrote at 2006-1-28 10:30 +0100: >Hi, after googling and RTFM I have no other option but ask you for help. > >I have the following DTML document: > > >ata"> >Select the file: > >>"> > > > > >And here is the checkTheFile python script: >## Script (Python) "checkTheFile" >##bind container=3Dcontainer >##bind context=3Dcontext >##bind namespace=3D >##bind script=3Dscript >##bind subpath=3Dtraverse_subpath >##parameters=3D >##title=3D >## ># Import a standard function, and get the HTML request and response objec= >ts. >from Products.PythonScripts.standard import html_quote >request =3D container.REQUEST >RESPONSE =3D request.RESPONS > > >filename=3Dhtml_quote(request.form['the_file'].filename) >context.fs.rpt.manage_addFile(filename, request.form['the_file'], >content_type=3D"text/xml") ># the next line does'n work: >file_content=3Drequest.form['the_file'].read() ># EOF > >I need to temporary save uploaded file then I have to validate it. But >I've received the following error message: > >Site error: >Error Type: AttributeError >Error Value: read Whenever you get an "Error", you should look at the traceback (to be found in your "error_log" in the Zope "Root Folder"). It tells you where the error occurred. The code you show above should not result in an "AttributeError: read". However, it has some other problems: * "manage_addFile" has read the uploaded file; after the call, it is positioned at its end. Your "read" will therefore always return ''. You should call a "seek(0)" before you try to read the file again. * Your code is less well readable than possible. This could be improved by a definition "file = request.form['the_file']" and than using "file" rathen than "request.form['the_file']" over and over again. -- Dieter ___ 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 )
Re: [Zope] Yet another newbie question (file upload and python scripts)
--On 28. Januar 2006 11:20:12 -0800 David <[EMAIL PROTECTED]> wrote: --- Janusz, Zope objects of meta-type FILE do not have a read(). But with python there always is a way, eg There is no meta-type FILE but only File. But this does not matter in this case since an uploaded file *does* have a read() method. The code looks mostly ok. I would look directly at the REQUEST object to figure out what the request really contains. -aj pgp9w4kR7WBK3.pgp Description: PGP signature ___ 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 )
Re: [Zope] Yet another newbie question (file upload and python scripts)
Janusz Zamecki wrote: Hi, after googling and RTFM I have no other option but ask you for help. I have the following DTML document: Select the file: >"> And here is the checkTheFile python script: ## Script (Python) "checkTheFile" ##bind container=3Dcontainer ##bind context=3Dcontext ##bind namespace=3D ##bind script=3Dscript ##bind subpath=3Dtraverse_subpath ##parameters=3D ##title=3D ## # Import a standard function, and get the HTML request and response objec= ts. from Products.PythonScripts.standard import html_quote request =3D container.REQUEST RESPONSE =3D request.RESPONS filename=3Dhtml_quote(request.form['the_file'].filename) context.fs.rpt.manage_addFile(filename, request.form['the_file'], content_type=3D"text/xml") # the next line does'n work: file_content=3Drequest.form['the_file'].read() # EOF I need to temporary save uploaded file then I have to validate it. But I've received the following error message: Site error: Error Type: AttributeError Error Value: read I've tested it on zope 2.7.7 and 2.9.0 on suse 10.0. (python 2.4.1). So, It is obvious to me that I've made a mistake, but I have no idea where it is? I hope that someone could show me the right way Best regards to all, Janusz Janusz, Zope objects of meta-type FILE do not have a read(). But with python there always is a way, eg ListOfLines = str(context.someFileObject).split('\n') # if its a delimited file, this has worked for me in the past for line in listOfLines: doValidations(line) ? David ___ 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 )
[Zope] Yet another newbie question (file upload and python scripts)
Hi, after googling and RTFM I have no other option but ask you for help. I have the following DTML document: Select the file: >"> And here is the checkTheFile python script: ## Script (Python) "checkTheFile" ##bind container=3Dcontainer ##bind context=3Dcontext ##bind namespace=3D ##bind script=3Dscript ##bind subpath=3Dtraverse_subpath ##parameters=3D ##title=3D ## # Import a standard function, and get the HTML request and response objec= ts. from Products.PythonScripts.standard import html_quote request =3D container.REQUEST RESPONSE =3D request.RESPONS filename=3Dhtml_quote(request.form['the_file'].filename) context.fs.rpt.manage_addFile(filename, request.form['the_file'], content_type=3D"text/xml") # the next line does'n work: file_content=3Drequest.form['the_file'].read() # EOF I need to temporary save uploaded file then I have to validate it. But I've received the following error message: Site error: Error Type: AttributeError Error Value: read I've tested it on zope 2.7.7 and 2.9.0 on suse 10.0. (python 2.4.1). So, It is obvious to me that I've made a mistake, but I have no idea where it is? I hope that someone could show me the right way Best regards to all, Janusz signature.asc Description: OpenPGP digital signature ___ 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 )