【发布时间】:2015-12-16 14:37:19
【问题描述】:
如何使用 Bottle 框架在 Python 中发送文件作为 HTTP 请求的响应?
对于上传此代码适用于我:
@route('/upload', method='POST')
def do_upload():
category = request.forms.get('category')
upload = request.files.get('upload')
name, ext = os.path.splitext(upload.raw_filename)
if ext not in ('.png','.jpg','.jpeg'):
return 'File extension not allowed.'
save_path = category
upload.raw_filename = "hoho" + ext
upload.save(save_path) # appends upload.filename automatically
return 'OK'
【问题讨论】:
标签: python http download wsgi bottle