def post(self):
# url and filename are sent in a JSON encoded blob
post_data = tornado.escape.json_decode(self.request.body)
nb_url = post_data['nb_url']
nb_name = base64.b64decode(post_data['nb_name']).decode('utf-8')
force_download = post_data['force_download']
file_path = os.path.join(os.getcwd(), nb_name)
if os.path.isfile(file_path):
if not force_download:
raise HTTPError(409, "ERROR: File already exists.")
response = request_session.get(nb_url, stream=True)
with open(file_path, 'wb') as fd:
# TODO: check if this is a good chunk size
for chunk in response.iter_content(1024):
fd.write(chunk)
self.write(nb_name)
self.flush()
评论列表
文章目录