import web
import time
#import httplib2
import httplib

urls = ('/','Index',
       '/commit', 'Commit',
	   '/success','showSuccess',
)

class Upload:
    def GET(self):
        web.header("Content-Type","text/html; charset=utf-8")
        return """<html><head></head><body>
<form method="POST" enctype="multipart/form-data" action="">
<input type="file" name="myfile" />
<br/>
<input type="submit" />
</form>
</body></html>"""


BUF_SIZE = 262144
class Commit:
    def POST(self):
        file_name = 'file_name'
        file_path = os.path.join('file_path', file_name)
        f = None
        try:
            f = open(file_path, "rb")
            webpy.header('Content-Type','application/octet-stream')
            webpy.header('Content-disposition', 'attachment; filename=%s.dat' % file_name)
            while True:
                c = f.read(BUF_SIZE)
                if c:
                    yield c
                else:
                    break
        except Exception, e:
            print e
            yield 'Error'
        finally:
            if f:
                f.close()

if __name__ == "__main__":
   app = web.application(urls, globals()) 
   app.run()