Thanks Cameron, You are the first to respond and I thank you very much. However I have resolved this through hard work and a lot of mistakes... It ended up being very similar to your suggestion below however i added the ability to put a user friendly name for the file which then becomes the zope object name... It turned out perfectly. If you would like to see the py script its below. I had repurposed this how-to http://www.zopelabs.com/cookbook/995659423 I changed it slightly to enable concurrent db referencing.. It works buetifally. Thanks again. REQUEST=context.REQUEST sentFiles = {} for key in context.REQUEST.keys(): # get all the ids if key[:5]=='file_' and key[-3:]=='_id': # we find id file_XXX_id sentFiles[REQUEST[key]]='' for key in context.REQUEST.keys(): if key[:5]=='file_' and key[-3:]!='_id': #we've got a file #found its id and make sure file exists if sentFiles.has_key(REQUEST[key+'_id']) and REQUEST[key].filename: sentFiles[REQUEST[key+'_id']]=REQUEST[key] else: del sentFiles[REQUEST[key+'_id']] #remove keys that dont have files #now that we have created a dictionary w/ a id and we know its value is a uploaded file #lets write them to the context's folder for k in sentFiles.keys(): container.Files.manage_addFile(k, sentFiles[k]) res=context.dbInsertMethod() return 'Finished updating the database and adding ' + str(len(sentFiles)) + ' files. <a href="add">Add More</a>, <a href="browse">Browse</a> or <a href="index_html">Go Home</a>' --- J Cameron Cooper <jccooper@jcameroncooper.com> wrote:
I have a form which i require to do two things
with.
1. Insert data into a MySQLdb table. 2. Upload a file to the zope file system.
I can do both indiviually no problems.
I want to do this so i have a mysql refrence to the file but dont want the file actually in the mysql db. I want all this data linked.
My problem is that I want to do both at once by clicking the same submit button.
I was thinking that maybe I could pass all data to a py script and have it deal with the input one at a time. But I couldnt come up with the syntax. It doesnt seem to gel in my dense skull.
Any idea's?
Hard to say without more context, but I'll give it a shot:
There's two components:
1) a form that has fields for your database data (a, b, c) and your file. The form's action is...
2) a script to do the processing. It calls a ZSQL method to do the database insert and adds a file to the ZODB (probably named after your primary key.)
So in your HTML upload page:
... <form method="post" action="multiScript"> ... <input type="text" name="key" /> <input type="text" name="a" /> <input type="text" name="b" /> ... <input type="file" name="upfile" /> ... </form> ...
and in the Python Script:
request = container.REQUEST ... context.someZSQLMethod(key=request.key, a=request.a, b=request.b) context.manage_addFile(id=request.key, file=request.upfile, title="title",
precondition="precondition", content_type="content_type") # note that everything after id is actually optional ... # return something or redirect
This is of course only a skeleton, but I think all the fundamentals are there.
--jcc
__________________________________________________ Do you Yahoo!? Yahoo! Tax Center - forms, calculators, tips, more http://taxes.yahoo.com/