You forgot the enctype attribute of the form tag <form name="uploadform" enctype="multipart/form-data">
2010/10/31 He Jibo <hej...@gmail.com>: > Hi, Can someone teach me how to parse a file uploaded to GAE? > > I am writing a feature that users can upload a .csv file, and save > data into the data model. I have already implemented the uploading, > see the link below: > http://gae-hejibo.appspot.com/TestUpload > But I do not know how to parse it, and save in my data model. Below is > my html and processing code. I can upload a csv file, but the data in > the csv is not saved into the data model. Can someone teach me what's > wrong with my code, and how should I do? Thanks! > > ------------------html file code-------------------- > <form name="uploadform"> > <div> > </p>CSV File(Comma Separated Value) File*: </p> > <input type="file" > name="uploadfilename"/> > <input type="submit" value="Upload"></div> > </form> > > > ------------------processing code-------------------- > class TestUpload(webapp.RequestHandler): > '''add item using .csv file''' > def get(self): > path = > os.path.join(os.path.dirname(__file__),'template','TestUpload.html') > self.response.out.write(template.render(path, {})) > def post(self): > fileReader = open(self.request.get('uploadfilename')) > csv_file=self.request.get('uploadfilename') > fileReader = csv.reader(csv_file.split("\n")) > > > for row in fileReader: > cell = row.split('\t') > > fourchoice = FourChoices() > fourchoice.description = cell[0] > fourchoice.choiceA = cell[1] > fourchoice.choiceB = cell[2] > fourchoice.choiceC = cell[3] > fourchoice.choiceD = cell[4] > fourchoice.a = cell[5] > fourchoice.b = cell[6] > fourchoice.c = cell[7] > fourchoice.answer = cell[8] > fourchoice.put() > path = > os.path.join(os.path.dirname(__file__),'template','debug.html') > self.response.out.write(template.render(path, > {'description':'fileupload'})) > > -- > You received this message because you are subscribed to the Google Groups > "Google App Engine" group. > To post to this group, send email to google-appeng...@googlegroups.com. > To unsubscribe from this group, send email to > google-appengine+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/google-appengine?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to google-appeng...@googlegroups.com. To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.