John Mudd
JohnMudd at mindspring.com
Fri May 7 07:25:09 EST 2004
Thanks for the latest code. I think my problem is somewhere else though. Even with this code my field is treated as a string. I forced the "found.append(item)" to be executed and I am able to execure the file.read() for my object. But that just gives me a copy of the file name, not the contents. The field is a file input field on my form. I get the "Browse..." button, select a file but, so far, I can't get the contents of the file. John On Fri, 2004-05-07 at 06:45, David Fraser wrote: > No, this doesn't contain the correct code... > You need to replace the line as follows (and two others like it): > - if isinstance(item.file, FileType): > + if isinstance(item.file, FileType) or \ > + isinstance(getattr(item.file, 'file', None), > FileType): > BTW Grisha has committed this code to CVS so it should be in the next > version of mod_python (thanks Grisha)... > > John Mudd wrote: > > >Perfect timing! I just found that thread myself via Gogle and I just > >checked my 3.1.3 version of util.py. It seems to contain the correct > >code. Here it is: > > > > > > def __getitem__(self, key): > > """Dictionary style indexing.""" > > if self.list is None: > > raise TypeError, "not indexable" > > found = [] > > for item in self.list: > > if item.name == key: > > if isinstance(item.file, FileType): > > found.append(item) > > else: > > found.append(StringField(item.value)) > > if not found: > > raise KeyError, key > > if len(found) == 1: > > return found[0] > > else: > > return found > > > > > > > > > >I added debug code inside this method and here are the results: > > > >item=Field('inputJar', 'zopeIntro.txt') > >item.type='text/plain' > >item.type_options={} > >type(item)=<type 'instance'> > > > > > > > > > > > >Someone else mad a suggestion that I'm not setting my content_type > >correctly. Here's what I'm using. > > > >def handler(req): > > req.content_type = 'text/html' > > > > > > > >I tried switching to req.content_type = 'multipart/form-data'. That did > >have an effect. Now I get a popup from my browser asking if I want to > >save the file or open it with an application. > > > > > > > >Any suggestions? > > > > > > > >On Fri, 2004-05-07 at 05:04, Volodya wrote: > > > > > >>On Thu, May 06, 2004 at 01:21:29PM -0400, John Mudd wrote: > >> > >> > >>>(Sorry if you see this msg twice. I submitted this earlier today by under a non-member email address.) > >>> > >>>I'm trying to upload a file. I specified a "file" type input field in my HTML, it displays as expected with the "Browse..." button, I'm able to select a file but... > >>> > >>>When I look in the FieldStorage dictionary for the field I only get a String type field that is the file name. I was expecting a "Field" type object that would provide access to the file name and contents. > >>> > >>>What am I missing? > >>> > >>> > >>Check this thread : > >> > >> http://www.modpython.org/pipermail/mod_python/2004-March/015224.html > >> > >> > >> > >>_______________________________________________ > >>Mod_python mailing list > >>Mod_python at modpython.org > >>http://mailman.modpython.org/mailman/listinfo/mod_python > >> > >> > > > >_______________________________________________ > >Mod_python mailing list > >Mod_python at modpython.org > >http://mailman.modpython.org/mailman/listinfo/mod_python > > > > > > >
|