Hello,
I got problem with reading from uploaded xls just after forms.accept.
Code looks like this:
program.py
---
db.define_table('files',
SQLField('file', 'upload'),
SQLField('filename')
)
default.py
----
def upload():
# first form - working
# form = FORM('Upload file: ',
# INPUT(_name='file', _type='file'),
# INPUT(_type='submit'))
# second form - not working
form = SQLFORM(db.files, fields = ['file'])
fileuploaded = ''
sheetnr = 0
if form.accepts(request.vars, session):
fileuploaded = "File uploaded"
sheetnr = load_to_db(request.vars.file.file.read())
return dict(form = form, status = fileuploaded, sheetnr = sheetnr)
def load_to_db(a):
book = xlrd.open_workbook(file_contents = a)
return book.nsheets
Form not connected to DB works, and file can be read without any
problems. When I'm trying to do the same with saving file on disk I
receive error from xlrd: "TypeError: coercing to Unicode: need string
or buffer, NoneType found". Is there any way to do this ? Or maybe
there's some way to read path to the newly uploaded file so I can pass
filename instead of file_content to xlrd ?
Thank you for help in advance! :)
M