Hi guys,
I tried using the above code but ran into some problems. I am able to
upload the file but unable to access the contents of the file. The
file is uploaded - I know because the line "print
request.vars.import_csv" shows the file contents. However,
"request.vars.import_csv.file.read()" appears to return an empty
string. I went through as many docs as I could find, and everything
points that this should work? Do you know what could be the problem or
a quickfix? Here is the code:
def import_csv():
from gluon.sqlhtml import form_factory
form=form_factory(SQLField('import_csv','upload'))
if form.accepts(request.vars,session) and request.vars.import_csv !
= '':
#session.flash='Received: %s' % request.vars.import_csv
print request.vars.import_csv # Shows file content
print request.vars.import_csv.file.read() # shows nothing,
just empty string
print request.vars.import_csv.filename # shows filename
session.flash='Received: %s' % request.vars.import_csv
# must restrict file size at some point
redirect(URL(r=request,f='import_csv'))
elif form.errors:
session.flash = 'error: please upload a file'
# print len(request.vars.import_csv.file.read()),'bytes'
return dict(form=form)
Thanks!
Vic
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---