Hi,

What you did is ok, except you are trying to send the content of a binary 
file (xls) to the template to be printed out on screen.  This will cause 
the UnicodeDecodeError since you have binary data, not text.

So the content of x['calendar_file'].value is fine, you need to extract the 
information from it and send the data to the template.  But that outside of 
the scope of webpy.

I personally would only allow CSV file to be uploaded, so it easily 
parsable.

Moc


On Wednesday, 19 February 2014 16:07:22 UTC-5, Jessica Le wrote:
>
> Hi all,
>
>
> What I want to be able to do is have a file upload button that lets the 
> user upload an .xls file and either save it in memory or to the server, so 
> I can take the file and parse it for later use. I have tried using the file 
> upload recipe on the website (http://webpy.org/cookbook/fileupload), but 
> I get an error when I try to upload an Excel file, but it works fine for a 
> .txt document. Some have suggested using an Excel library (xlrd) to do so, 
> but that library would only work AFTER I upload the file. I need to know 
> how to upload the Excel file without it throwing an error. The error that I 
> receive when I upload the Excel file is UnicodeDecodeError. Is there 
> another way to upload an Excel file other than using webpy's file upload 
> recipe? I'm starting to think I should switch frameworks, since there isn't 
> much documentation for webpy...
>
>
> Python CODE: 
>
> class index:
>     def GET(self):
>     web.header("Content-Type","text/html;")
>     return render.index(form)
>     def POST(self):
>         x = web.input(calendar_file={})
>
> calendar_contents = x['calendar_file'].value
> return render.results(calendar_contents)
>
> ------
> HTML CODE: 
>
> $def with (form) 
> <div class="well well-lg">
> <h4> GENERATE ON-CALL SCHEDULE </h4>
> <form role="form" method="POST"enctype="multipart/form-data" action="">
> <div class="form-group">
> <label form="inputFile">Upload File</label>
>     <input type="file"  name="calendar_file" id="file"/>
> </div>
>   <button type="submit" class="btn btn-default" 
> value="upload">Submit</button>
> </form>
> </div>
>

-- 
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/webpy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to