[Zope] manage_addFile method
Tino Wildenhain
tino at wildenhain.de
Thu Nov 4 16:55:41 EST 2004
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
More information about the Zope
mailing list