[Zope] python script to upload file with dynamically generated filename
David Siedband
david@calteg.org
Mon, 28 Jul 2003 15:56:02 -0700
I'm working on a script to upload a file to a file repository (zope
folder) and generate a custom file name. My intention is to use a
LocalFS object (instead of the Zope folder) once this bit is sorted.
My goal is to rename the file based on the filename and extension
variables that I'm passing to the script.
The part I'm stuck on is the syntax of this part:
manage_addFile(id='%s%s % (filename, extension)', title='', file=file)
In this example I'd like to set the id to 'thefile.jpg'
TIA,
David
+++++++++++++ [ script ] +++++++++++++++
#parameters file, filename='thefile', extension='.jpg'
"""
Uploads a file to the repository with a crafted id.
"""
from Products.PythonScripts.standard import url_quote
# crafts the filename and creates the file
container.Files.manage_addProduct['OFSP'].manage_addFile(id='%s%s %
(filename, extension)', title='', file=file)
# creates the success message
message="The file '%s' has been added to the repository." % file.filename
# redirects to the file repository interface page
return context.REQUEST.RESPONSE.redirect("%s/repository_html?message=%s"
% (container.absolute_url(), url_quote(message)))