7

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.
4

2 回答 2

10

self.request.files应该没事。这是一个例子

于 2012-10-09T10:33:19.907 回答
6
@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 页面上找到。

于 2012-10-09T10:48:08.060 回答