I must be doing something very wrong.  The field I get back does not
seem to have any of the components it should have.

Here is my controlller:

def import_csv():
    from gluon.sqlhtml import form_factory
    form=form_factory(SQLField('import_csv','upload'))
    if form.accepts(request.vars,session):
        request.flash='Received: %s'%request.vars.import_csv
        #do more processing here
    return dict(form=form)

And here is the view:

{{extend 'layout.html'}}
<h1>This is the meets/import_csv.html template</h1>
{{=form}}
{{=BEAUTIFY(request.vars.import_csv.filename if
request.vars.import_csv else '')}}

The if clause above was to see if the field contained anything under
"import_csv".  It did not.

I was trying to follow the information in the manual on page 177 but
there seemed to be missing information (like the input field itself).

I am currently using version 1.56.3.  I plan to update as soon as the
current swim meet is over and I can take the site down for awhile as I
work on it.

On Mar 12, 6:15 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> you can get the file content from
>
>   request.vars.my_field_name.file.read()
>
> and the file name from
>
>   request.vars.my_field_name.filename
>
> hope this helps.
>
> On Mar 12, 7:55 pm, Joe  Barnhart <joe.barnh...@gmail.com> wrote:
>
> > Let me preface this by explaining that I am a noob at creating
> > websites.  This is probably so simple that anyone who's been around
> > the block knows the answer and is thus confused at the empty-
> > headedness of my question.
>
> > I wanted to take advantage of web2py's built-in handling of update
> > fields -- it pops up a file chooser and allows the user to pick the
> > the file to upload on his local computer.  The file is then streamed
> > up to the server running web2py and usually placed in the "uploads"
> > directory and linked into a database table.  In my case, rather than
> > storing the file or a reference to it in a database, I wish to process
> > the file immediately in the controller and store the processed
> > results.
>
> > I can create a form using form_factory with a single SQLField
> > definition for a field of type "upload".  When I invoke this form it
> > correctly displays a file chooser and lets me pick a file.  After that
> > -- nothing.  The form.accepts() part of the controller is never
> > triggered.  I can look at the contents of the
> > request.vars.my_field_name and see that it now contains an object of
> > FieldStorage, but I'm not sure what it is good for.
>
> > Thank you for your patience and responses.
>
> > On Mar 12, 5:23 pm, Wes James <compte...@gmail.com> wrote:
>
> > > On Thu, Mar 12, 2009 at 6:20 PM, Joe Barnhart <joe.barnh...@gmail.com> 
> > > wrote:
>
> > > > Actually, I need to process the CSV file before it can be inserted
> > > > into the database.  I was hoping to upload it to disk (or even memory
> > > > as the files are small), do the processing, and commit the changes to
> > > > db.
>
> > > How about uploading it to the static files folder in web2py admin then
> > > process if from there?  Not sure what you are trying to do though??
> > > upload via browser or copy over via sftp? then process??
> > > -wj
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to