title: Bottle upload xlsx and process with xls2db
body: <p>I am looking to grab a xlsx file from a bottle upload and send the file to the xls2db module to populate a sqlite db but I don't seem to be passing the file properly.
  #</p>
  
  <pre><code>     @route('/',method="GET")   # Select the xls sheet from this route
  def testRoute():
      return ('''&lt;/br&gt;
             &lt;h1&gt; Select the spreadsheet&lt;/h1&gt;
             &lt;form action="/upload" method="post" enctype="multipart/form-data"&gt;
              &lt;input type="text" name="name" /&gt;
              &lt;input type="file" name="data" /&gt;
  
              &lt;input type="submit"/&gt;
         &lt;/form&gt;  ''')
  
  
  @route('/upload', method='POST')
  def do_upload():
      name = request.forms.name
      data = request.files.data
      if name and data and data.file:
          raw = data.file.read() # This is dangerous for big files
          filename = data.filename
          #return "Hello %s! You uploaded %s (%d bytes)." % (name,   filename, len(raw))
          upload_xls(raw, filename)
  </code></pre>
  
  <h1>connect to database drop the tables if they exist and convert xls sheet to sqlite database</h1>
  
  <pre><code>def upload_xls(raw, filename):
      conn = sqlite.connect("test_db.sqlite")
      cur = conn.cursor()
      f = filename
      data = raw
      cur.execute("DROP TABLE IF EXISTS Requests;")
      cur.execute("DROP TABLE IF EXISTS Complaints;")
      xls2db(data , "test_db.db")
      redirect("/work")
  </code></pre>
  
  <p>UPDATE - I am now getting this error.</p>
  
  <pre><code>    2016-02-16 22:16:55 ERROR:root:Traceback (most recent call last):
      2016-02-16 22:16:55 ERROR:root:  File "/usr/local/lib/python2.7/dist-packages/bottle.py", line 764, in _handle
      2016-02-16 22:16:55 ERROR:root:    return route.call(**args)
      2016-02-16 22:16:55 ERROR:root:  File "/usr/local/lib/python2.7/dist-packages/bottle.py", line 1575, in wrapper
     2016-02-16 22:16:55 ERROR:root:    rv = callback(*a, **ka)
     2016-02-16 22:16:55 ERROR:root:  File "/home/mcsl/mysite/bottle_app.py", line 91, in do_upload
     2016-02-16 22:16:55 ERROR:root:    upload_xls(file_path)
     2016-02-16 22:16:55 ERROR:root:  File "/home/mcsl/mysite/bottle_app.py", line 22, in upload_xls
     2016-02-16 22:16:55 ERROR:root:    xls2db(file_name, "test_db.db")
     2016-02-16 22:16:55 ERROR:root:  File "/home/mcsl/.local/lib/python2.7/site-packages/xls2db/__init__.py", line 29, in xls2db
    2016-02-16 22:16:55 ERROR:root:    wb = xlrd.open_workbook(infile)
    2016-02-16 22:16:55 ERROR:root:  File "/usr/local/lib/python2.7/dist-packages/xlrd/__init__.py", line 435, in open_workbook
    2016-02-16 22:16:55 ERROR:root:    ragged_rows=ragged_rows,
    2016-02-16 22:16:55 ERROR:root:  File "/usr/local/lib/python2.7/dist-packages/xlrd/book.py", line 87, in open_workbook_xls
    2016-02-16 22:16:55 ERROR:root:    ragged_rows=ragged_rows,
    2016-02-16 22:16:55 ERROR:root:  File "/usr/local/lib/python2.7/dist-packages/xlrd/book.py", line 594, in biff2_8_load
    2016-02-16 22:16:55 ERROR:root:    raise XLRDError("File size is 0 bytes")
   2016-02-16 22:16:55 ERROR:root:XLRDError: File size is 0 bytes
  </code></pre>
  
  <p>I can upload the file and I can now see it on the server but when I pass it to the function it is reporting that its empty.</p>
  
  <pre><code>    @route('/upload', method='POST')
      def do_upload():
          data = request.files.upload
          upload = request.files.get('upload')
          name, ext = os.path.splitext(data.filename)
          #check the file is an excel file
          if ext not in ( '.xls', '.xlsx'):
              return "File extension not allowed."
  
              save_path = "/home/mcslo/mysite".encode("utf-8")
              file_path= "{path}/{file}".format(path=save_path,        file=data.filename)
              raw = data.file.read() # This is dangerous for big file
  
             open_file = open(file_path, 'w')
             open_file.write(raw)
             open_file.close
             upload_xls(file_path)
  
  
      def upload_xls(file_name):
  file_name = file_name
  conn = sqlite.connect("test_db.sqlite")
  cur = conn.cursor()
  cur.execute("DROP TABLE IF EXISTS Requests;")
  cur.execute("DROP TABLE IF EXISTS Complaints;")
  xls2db(file_name, "test_db.db")
  redirect("/work")
  </code></pre>