在Python框架下通过http发送文件
如何使用瓶子框架在Python中发送一个文件作为HTTP请求的应答 对于上载,此代码适用于我:在Python框架下通过http发送文件,python,http,download,wsgi,bottle,Python,Http,Download,Wsgi,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
@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'
只需调用并返回其结果:
@route('/static/<filename:path>')
def send_static(filename):
return static_file(filename, root='/path/to/static/files')
@route(“/static/”)
def send_静态(文件名):
返回静态文件(文件名,根='/path/to/static/files')
当使用url/static/myfile.txt
调用该示例时,将返回内容文件/path/to/static/files/myfile.txt
其他SO问题(如)包含其他示例。我想知道使用
瓶子
提供静态文件是否可以,或者最好将nginx
放在前面?