Reading and uploaded csv file

58 views
Skip to first unread message

Alex

unread,
Oct 8, 2009, 11:37:51 AM10/8/09
to cherrypy-users
Hi all.

I'm working on a small webapp with cherrypy that read an uploaded CSV
file and transform it in XML.
Now my problem is that when I try to read the content of the uploaded
file with csv.reader the file seams to be empty, but when I look at
the content with myFile.file.read() I can see the expected content.
So how can I use the csv module to read and uploaded file?

Thanks in advance.

Here is the relevant part of the code (mostly taken from the
tutorial).

class FileDemo(object):

def index(self):
return """
<html><body>
<form action="upload" method="post" enctype="multipart/
form-data">
filename: <input type="file" name="myFile" /><br />
<input type="submit" />
</form>
</body></html>
"""
index.exposed = True

def upload(self, myFile):
out = """<html>
<body>
%s
</body>
</html>"""

csvfile = csv.reader(myFile.file) # when I look in th csvfile
it seams there are no rows
content = myFile.file.read() # here I can see the
expected content

....
Reply all
Reply to author
Forward
0 new messages