【问题标题】:File upload with Tornado使用 Tornado 上传文件
【发布时间】:2012-10-09 10:14:41
【问题描述】:

当使用put 请求时,如何在 Tornado 中访问上传的文件?

@require_basic_auth
class UploadFile(tornado.web.RequestHandler):
    def put(self, params):
        path = calculate_path(params)
        # TODO: create an empty binary file at path and then copy 
        # the request input stream to it.

【问题讨论】:

    标签: python python-3.x tornado


    【解决方案1】:

    self.request.files 应该没问题。这是example

    【讨论】:

      【解决方案2】:
      @require_basic_auth
      class UploadFile(tornado.web.RequestHandler):
          def put(self, params):
              path = calculate_path(params)
              with open(path, 'wb') as out:
                  body = self.request.get_argument('data')
                  out.write(bytes(body, 'utf8'))        
      

      ...正是我所需要的。

      在一些 ActiveState 页面上找到。

      【讨论】:

      • bytes 只接受一个参数(python 2.7),有错字吗?
      猜你喜欢
      • 2014-12-03
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-16
      相关资源
      最近更新 更多