Hello. Is there a way to pass a variable for the id argument to manage_addFile? I want the user to be able to choose the id for a file that they wish to upload instead of hard-coding it in as a string literal. I have tried the following code which is inside a Python script: fileName = REQUEST.form['publicationsFile'] context.manage_addFile(id=fileName, file=fileName, title=' ', precondition=' ', content_type='application/pdf') The error I get is as follows: Error Type: Bad Request Error Value: The id "<ZPublisher.HTTPRequest.FileUpload instance at 0x46a0170>" contains characters illegal in URLs. However, if I use a string literal, everything works fine. The following yields no errors but doesn't serve my purpose: fileName = REQUEST.form['publicationsFile'] context.manage_addFile(id='fileName', file=fileName, title=' ', precondition=' ', content_type='application/pdf') Also, if anyone knows of another method that could achieve the same purpose, please let me know. Any help would be greatly appreciated. Thanks. - Asad
On Thu, 4 Nov 2004 15:07:06 -0500 (EST), Asad Habib <ahabib@engin.umich.edu> wrote:
Hello. Is there a way to pass a variable for the id argument to manage_addFile? I want the user to be able to choose the id for a file that they wish to upload instead of hard-coding it in as a string literal.
NEVER trust input passed through a form as being free of malicious or downright unluckily selected characters! You can either choose the ID to be something generated randomly (write something to call thus : context.generate_a_random_id_for_me()), or even pass the string the user intended and try to fix any illegal characters ... if you like ;-) Problem with random IDs is - they might be taken so you can't even trust your own function - double-check! [You might want to acquire the container for the Z-Object you're creating and use it's objectIds() list to do that] Try passing your id-string as title, this field is for the elaborate stuff, id is just a handle - I'd just show it if no title is set. [Z-Object.title_or_id()] You can even have HTML in your titles ... -- --- The Count | http://count0.dyndns.org/members/count0 # Programmers don't DIE - they just GOSUB without RETURN
Hi, Am Do, den 04.11.2004 schrieb Asad Habib um 21:07:
Hello. Is there a way to pass a variable for the id argument to manage_addFile? I want the user to be able to choose the id for a file that they wish to upload instead of hard-coding it in as a string literal.
I have tried the following code which is inside a Python script:
fileName = REQUEST.form['publicationsFile'] context.manage_addFile(id=fileName, file=fileName, title=' ', precondition=' ', content_type='application/pdf')
The error I get is as follows:
Error Type: Bad Request Error Value: The id "<ZPublisher.HTTPRequest.FileUpload instance at 0x46a0170>" contains characters illegal in URLs.
However, if I use a string literal, everything works fine. The following yields no errors but doesn't serve my purpose:
fileName = REQUEST.form['publicationsFile'] context.manage_addFile(id='fileName', file=fileName, title=' ', precondition=' ', content_type='application/pdf')
Also, if anyone knows of another method that could achieve the same purpose, please let me know. Any help would be greatly appreciated. Thanks.
if fileName is the name of the form element (<input type="file" name="fileName" /> Then it does not contain the name of the file but the file itself. The filename of that file is an attribute of that object. Access it via fileName.filename (You should consider a better name for your form element) Regards Tino
In addition to the other advice you have received, watch out for the filename containing the full path in platform specific formats (i.e. :: from Macs and \\ from Windows). Cliff Asad Habib wrote:
Hello. Is there a way to pass a variable for the id argument to manage_addFile? I want the user to be able to choose the id for a file that they wish to upload instead of hard-coding it in as a string literal.
I have tried the following code which is inside a Python script:
fileName = REQUEST.form['publicationsFile'] context.manage_addFile(id=fileName, file=fileName, title=' ', precondition=' ', content_type='application/pdf')
The error I get is as follows:
Error Type: Bad Request Error Value: The id "<ZPublisher.HTTPRequest.FileUpload instance at 0x46a0170>" contains characters illegal in URLs.
However, if I use a string literal, everything works fine. The following yields no errors but doesn't serve my purpose:
fileName = REQUEST.form['publicationsFile'] context.manage_addFile(id='fileName', file=fileName, title=' ', precondition=' ', content_type='application/pdf')
Also, if anyone knows of another method that could achieve the same purpose, please let me know. Any help would be greatly appreciated. Thanks.
- Asad
_______________________________________________ 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 )
participants (4)
-
Asad Habib -
Cliff Ford -
The Count -
Tino Wildenhain