File upload gotcha...

I'm currently working on some much-needed updates to an AppEngine service that processes and serves content based on a CSV version of a spreadsheet. One of these new features is the ability to upload the spreadsheet via an HTML form. Of course, being early-ish on a Sunday morning, there was a little head scratching...

<html>
  <body>
    <form action="/admin" method="post">
      <div><input type="file" name="csvfile" accept="text/csv"></div>
      <div><input type="submit" value="Update CSV"></div>
    </form>
  </body>
</html>

Looks ok, right? Not quite. self.request.get("csvfile") only returns the file name! I must be forgetting something. After my coffee kicked in, I took another look at it and facepalmed. The following modification returned what I wanted.

<form action="/admin" enctype="multipart/form-data" method="post">

Sure enough, adding the "enctype" attribute has my code returning the contents of the CSV file.

Moral of the story? Don't code before your morning intake of caffeine.