2012-10-09 2 views
7

put 요청을 사용할 때 토네이도에 업로드 된 파일에 액세스하려면 어떻게해야합니까?토네이도로 파일 업로드

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

답변

7
@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 페이지에서 발견되었습니다.

+0

'bytes'는 단 하나의 인자 (파이썬 2.7) 만 허용합니다. 오타가 있습니까? – daniel

10

self.request.files이어야합니다. 다음은 example입니다.