thanks need to convert the byte object into str object
e.g.

# download_csv
def download_csv():
    stream = StringIO()
    db.export_to_csv_file(stream, 
                          delimiter = ',', 
                          quotechar = '"', 
                          write_colnames = True, 
                          represent = False)
    response.headers['Content-Type'] = 'text/csv'
    response.headers['Content-Disposition'] = 'inline; 
filename="{0}.csv"'.format(request.function.replace('_', ' ').title() )
    return stream.getvalue()

# upload_csv
def upload_csv():
    header = spt_form_constructor.form_header(T('Upload CSV') )
    form = FORM(INPUT(_type = 'file', _name = 'csv_file'),
                INPUT(_type = 'submit', _value = T('Import') ) )
    if form.process().accepted:
        if request.vars.csv_file != None:
*            csv_file = request.vars.csv_file.file.read()*
*            text_obj = csv_file.decode('UTF-8')*
*            db.import_from_csv_file(StringIO(text_obj) )*

            response.flash = T('Form accepted')
    elif form.errors:
        response.flash = T('Form has errors')
    else:
        response.flash = T('Please fill the form')
    return dict(header = header, form = form)

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/67a89a32-bb62-4df2-be58-b40e3d5801e5n%40googlegroups.com.

Reply via email to