zoukankan      html  css  js  c++  java
  • 一个tornado框架下的文件上传案例

    • html部分----使用了form表单,注意三要素 method="post"  action="/loaddata" enctype="multipart/form-data"
    <form method="post" id="postform" action="/loaddata" enctype="multipart/form-data">
          <div class="pricing-header px-3 py-3 pt-md-5 pb-md-4 mx-auto text-center">
            <h3 class="display-4">选择要读取的文件</h3>
            <p class="lead">
              <input type="file" name="damnfile" id="excelfile" class="form-control">
            </p>
          </div>
          <div class="container">
          <div class="card-deck mb-6 text-center">
              <div class="card mb-6 box-shadow">
              <div class="card-header">
                <h4 class="my-0 font-weight-normal">Free</h4>
              </div>
                <div class="card-body"  style="height:600px">
                <h1 class="card-title pricing-card-title">$0 <small class="text-muted">/ mo</small></h1>
                    <textarea cols="100%" rows="18">
                    </textarea>
                <button type="submit" id="postbtn" class="btn btn-lg btn-block btn-outline-primary">Sign up for free</button>
              </div>
            </div>
          </div>
    
          <footer class="pt-4 my-md-5 pt-md-5 border-top">
            <div class="row">
              <div class="col-12 col-md">
                <img class="mb-2" src="https://getbootstrap.com/assets/brand/bootstrap-solid.svg" alt="" width="24" height="24">
                <small class="d-block mb-3 text-muted">&copy; 2017-2018</small>
              </div>
              <div class="col-6 col-md">
                <h5>Features</h5>
                <ul class="list-unstyled text-small">
                  <li><a class="text-muted" href="#">Cool stuff</a></li>
                  <li><a class="text-muted" href="#">Random feature</a></li>
                  <li><a class="text-muted" href="#">Team feature</a></li>
                  <li><a class="text-muted" href="#">Stuff for developers</a></li>
                  <li><a class="text-muted" href="#">Another one</a></li>
                  <li><a class="text-muted" href="#">Last time</a></li>
                </ul>
              </div>
              <div class="col-6 col-md">
                <h5>Resources</h5>
                <ul class="list-unstyled text-small">
                  <li><a class="text-muted" href="#">Resource</a></li>
                  <li><a class="text-muted" href="#">Resource name</a></li>
                  <li><a class="text-muted" href="#">Another resource</a></li>
                  <li><a class="text-muted" href="#">Final resource</a></li>
                </ul>
              </div>
              <div class="col-6 col-md">
                <h5>About</h5>
                <ul class="list-unstyled text-small">
                  <li><a class="text-muted" href="#">Team</a></li>
                  <li><a class="text-muted" href="#">Locations</a></li>
                  <li><a class="text-muted" href="#">Privacy</a></li>
                  <li><a class="text-muted" href="#">Terms</a></li>
                </ul>
              </div>
            </div>
          </footer>
        </div>
        </form>
    • python部分
    class loaddata(RequestHandler):
            def post(self):
            sourcefile =self.request.files['damnfile']
            print(type(sourcefile))
            for i in sourcefile:
                print(i)
            for meta in sourcefile:
                filename = meta['filename']
                import os
                import time
                #realpath = os.path.(__file__)
                #print(realpath)
                with open("E:\"+filename ,"wb") as writer:
                    writer.write(meta['body'])
  • 相关阅读:
    Delphi 正则表达式之TPerlRegEx 类的属性与方法(3): Start、Stop
    Delphi 正则表达式之TPerlRegEx 类的属性与方法(2): 关于子表达式
    Delphi 正则表达式之TPerlRegEx 类的属性与方法(1): 查找
    Delphi 正则表达式语法(10): 选项
    Delphi 正则表达式语法(9): 临界匹配
    Delphi 正则表达式语法(8): 引用子表达式
    Delphi 正则表达式语法(7): 匹配转义字符
    看阿里P7讲MyBatis:从MyBatis的理解以及配置和实现全帮你搞懂
    公司新来的小姐姐不懂java中的static关键字,这样给她描述不香吗?
    2020阿里,字节跳动,JAVA岗(一线企业校招、社招)面试题合集
  • 原文地址:https://www.cnblogs.com/saintdingspage/p/10444967.html
Copyright © 2011-2022 走看看